why does the current folder stop being usable?

If none of the more specific forums is the right place to ask

why does the current folder stop being usable?

Postby MagicPoulp » 2020-11-18 08:35

why the current folder stops being usable?
Sometimes in my git repo, I get this error, and I have to do "cd; cd -"
sh: 0: getcwd() failed: No such file or directory

I am using a webpack watch and the folder is on a mounted file with cifs
here is the fstab entry for the mounting.
//REPLACED_SECRET_PATH cifs user=externo,password=REPLACED,uid=1000,gid=1000,mfsymlinks

note:
this thead gives a hint:
https://askubuntu.com/questions/286467/ ... -directory
MagicPoulp
 
Posts: 402
Joined: 2018-11-05 21:30

Re: why does the current folder stop being usable?

Postby LE_746F6D617A7A69 » 2020-11-19 21:41

Probably You have already discovered, that in Linux-based OS it's possible to delete and re-create a directory or file which is currently used by some other program. Whether this is a feature or bug, depends on a point of view, but there are practical reasons to have such functionality.
Anyway, in such case the fstat structure is changed (see fstat(2) )

The applications which have already obtained a file descriptor for that deleted/re-created file or directory will obviously return faults, because their file descriptors are no longer valid -> this also affects the shells -> that's why it's required to execute the "cd" command again.
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 414
Joined: 2020-05-03 14:16

Re: why does the current folder stop being usable?

Postby MagicPoulp » 2020-11-20 05:29

It seems dangerous that anything would delete recreate my folders. I don't think so.

IT seems to me more related to how mounting cifs works. And also related to a windows VM running a nodejs process on that same cifs.
MagicPoulp
 
Posts: 402
Joined: 2018-11-05 21:30

Re: why does the current folder stop being usable?

Postby LE_746F6D617A7A69 » 2020-11-20 21:32

MagicPoulp wrote:It seems dangerous that anything would delete recreate my folders. I don't think so.
IT seems to me more related to how mounting cifs works. And also related to a windows VM running a nodejs process on that same cifs.
I was referring to the article from the askubuntu.com which You've referenced. Unmounting a filesystem also invalidates all the currently used file/directory descriptors.

But I think that We need more details to explain what is actually happening. I'm guesing that the directory in question is just re-created during project synchronization (what invalidates the file/directory descriptors).
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 414
Joined: 2020-05-03 14:16

Re: why does the current folder stop being usable?

Postby p.H » 2020-11-22 16:58

LE_746F6D617A7A69 wrote:in Linux-based OS it's possible to delete and re-create a directory or file which is currently used by some other program.

No, it is not possible to delete a file or directory in use. You actually do not delete a file or directory with commands such as rm or rmdir, you only unlink it, i.e. delete the parent directory entry pointing to the inode. There may be multiple directory entries pointing to the same inode, each counting as a link. The file being used by a process also counts as a link. The file is actually deleted only after the last link is deleted.
p.H
 
Posts: 1521
Joined: 2017-09-17 07:12

Re: why does the current folder stop being usable?

Postby LE_746F6D617A7A69 » 2020-11-22 20:14

p.H wrote:
LE_746F6D617A7A69 wrote:in Linux-based OS it's possible to delete and re-create a directory or file which is currently used by some other program.

No, it is not possible to delete a file or directory in use. You actually do not delete a file or directory with commands such as rm or rmdir, you only unlink it, i.e. delete the parent directory entry pointing to the inode. There may be multiple directory entries pointing to the same inode, each counting as a link. The file being used by a process also counts as a link. The file is actually deleted only after the last link is deleted.

Nope.
Proof:
Open 2 terminal instances
terminal 1:
Code: Select all
mkdir testdir; cd testdir; touch testfile; ls
terminal 2:
Code: Select all
rm -r testdir; mkdir testdir; cd testdir; touch testfile2; ls
terminal 1:
Code: Select all
ls
Result: no files found, invalid descriptor for re-created directory 'testdir'
Now, in terminal 1:
Code: Select all
cd ..; cd testdir; ls
Now, the file 'testfile2' will be listed
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 414
Joined: 2020-05-03 14:16

Re: why does the current folder stop being usable?

Postby Islander » 2020-11-25 15:13

p.H wrote:You actually do not delete a file or directory with commands such as rm or rmdir, you only unlink it, i.e. delete the parent directory entry pointing to the inode. There may be multiple directory entries pointing to the same inode, each counting as a link. The file being used by a process also counts as a link. The file is actually deleted only after the last link is deleted.


That's true, but does "standing" in a directory (having it as current directory) count as the directory being in use?
Islander
 
Posts: 16
Joined: 2020-10-20 08:29

Re: why does the current folder stop being usable?

Postby LE_746F6D617A7A69 » 2020-11-25 20:40

Islander wrote:
p.H wrote:You actually do not delete a file or directory with commands such as rm or rmdir, you only unlink it, i.e. delete the parent directory entry pointing to the inode. There may be multiple directory entries pointing to the same inode, each counting as a link. The file being used by a process also counts as a link. The file is actually deleted only after the last link is deleted.


That's true, but does "standing" in a directory (having it as current directory) count as the directory being in use?

Nope, Test2:

terminal 1:
Code: Select all
mkdir testdir; cd testdir; touch testfile; less testfile
The file 'testfile' is now opened for read in terminal 1 (so it is opened for read, while the commands in terminal 2 are executed)
terminal 2:
Code: Select all
rm -r testdir; mkdir testdir; cd testdir; touch testfile2; less testfile2
The 'testdir' has been re-created (opened file 'testfile' has been deleted, and the file 'testfile2' is now opened for read in terminal 2)
terminal 1: type 'q' to quit less, then type 'ls'
Code: Select all
ls
The same result: no files found, invalid descriptor for re-created directory 'testdir'

Re-creation or deletion of a directory or file currently opened in some other program is possible in UNIX/BSD/Linux.
This also works on a very low level (descriptors) and if the above examples are not sufficient, I can spend another 5 minutes to demonstrate this behaviour on a C-code level.
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed
LE_746F6D617A7A69
 
Posts: 414
Joined: 2020-05-03 14:16


Return to General Questions

Who is online

Users browsing this forum: MagicPoulp and 25 guests

fashionable