This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.getcwd() fails on cifs share
Type: behavior Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dcuddihy, neologix
Priority: normal Keywords:

Created on 2013-03-22 22:12 by dcuddihy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg185014 - (view) Author: David Cuddihy (dcuddihy) Date: 2013-03-22 22:12
Calls to os.getcwd() can fail if issued from a cifs-mounted directory once any of the files or subdirectories have been changed remotely.  To recreate this: on Linux, mount a windows share using the mount.cifs command.  cd to the share and run python.   

Python 2.7.3 (default, Jul 24 2012, 10:05:38)
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type "help", "copyright", "credits" or "license for more information.
>>> import os
>>> print os.getcwd()
 /home/user/share
>>> exit()

That works.  Now, on the host machine, change a file in the current directory and save it.  The unix 'pwd' still works.  But now:
>>> import os
>>> print os.getcwd()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] No such file or directory
>>>

Even though the unix 'pwd' and 'ls' commands still work, so I know my share is still accessible.

If I umount and then remount the share, the problem goes away until a file is changed remotely.

I'm running this on Fedora 17.
msg185030 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2013-03-23 08:52
os.getcwd() just calls the libc getcwd(3), so Python's not the problem here.

it's likely an issue with the CIFS implementation (I guess you're using fuse?).

Could you post the output of:
$ strace python -c "import os; os.getcwd())"

upon failure?

> Even though the unix 'pwd' and 'ls' commands still work, so I know my share is still accessible.

'pwd' is likely your shell builtin, which doesn't call getcwd(). You could try with /bin/getcwd. As for 'ls', it doesn't walk the directory tree like getcwd() does.
msg189758 - (view) Author: David Cuddihy (dcuddihy) Date: 2013-05-21 14:13
I apologize for not posting the strace output - I didn't see the request until today.  

Libc getcwd() is indeed failing - when I run a c program which calls getcwd() and prints the output, the call to getcwd() fails - errno is ENOENT and the buffer is null.  

I will look elsewhere.  Thanks for getting me on the right track.
History
Date User Action Args
2022-04-11 14:57:43adminsetgithub: 61727
2013-05-21 14:13:28dcuddihysetmessages: + msg189758
2013-05-20 21:38:06neologixsetstatus: pending -> closed
resolution: not a bug
stage: resolved
2013-03-26 07:53:00neologixsetstatus: open -> pending
2013-03-24 18:40:27r.david.murraysettype: crash -> behavior
2013-03-23 08:52:37neologixsetnosy: + neologix
messages: + msg185030
2013-03-22 22:12:07dcuddihycreate