Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fchdir when available #1

Merged
merged 1 commit into from
Jun 3, 2013
Merged

Use fchdir when available #1

merged 1 commit into from
Jun 3, 2013

Conversation

ap
Copy link
Contributor

@ap ap commented May 25, 2013

Exactly what it says on the tin.

kazeburo added a commit that referenced this pull request Jun 3, 2013
Use fchdir when available
@kazeburo kazeburo merged commit 7a8d669 into kazeburo:master Jun 3, 2013
@ap ap deleted the fchdir branch June 3, 2013 03:19
@ap
Copy link
Contributor Author

ap commented Jun 3, 2013

Hm, I never explained why… You wrote “It’s reliable and faster” in Changes, and those are true, but for me the main reason to do it this way is another one.

Namely, by the time you try to chdir back to where you came from, permissions in some part of the path can have changed, so you cannot go back to where you were before through a path name. This is extremely rare of course, but it can happen. A more common possibility is that the directory may have been renamed or removed – and either a different directory of the same name created there (so you chdir to the wrong place) or not (so your chdir fails). In other words, a path name is not a stable identifier; it is subject to race conditions.

Using fchdir avoids this class of problem.

Sorry I failed to explain myself in the first place – and thanks for accepting the patch anyway!

@eserte
Copy link
Contributor

eserte commented Apr 13, 2016

I created a test which shows one of the advantages of the fchdir operation: #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants