Discussion:
rm -r removes directory but reports "cannot remove 'dir', directory not empty"
Saurabh T
2010-09-10 19:04:11 UTC
Permalink
This is with the latest cygwin and coreutils 8.5-2.
mkdir 1; echo $?
0
rm -fr 1; echo $?
0
ls 1
ls: cannot access 1: No such file or directory
mkdir 1; echo $?
0
rm -fr 1; echo $?
rm: cannot remove '1': Directory not empty
1
ls 1
ls: cannot access 1: No such file or directory

I have attached relevant strace output for the above two rm calls.
The differences seem to start at the "try_to_bin: Move" in the bad output.
Note that rmdir works fine in both cases when the directory is empty.

saurabh
Corinna Vinschen
2010-09-10 20:25:44 UTC
Permalink
Post by Saurabh T
This is with the latest cygwin and coreutils 8.5-2.
mkdir 1; echo $?
0
rm -fr 1; echo $?
0
ls 1
ls: cannot access 1: No such file or directory
mkdir 1; echo $?
0
rm -fr 1; echo $?
rm: cannot remove '1': Directory not empty
1
ls 1
ls: cannot access 1: No such file or directory
What is that I: drive? What does `mount' print as filesystem type of
/cygdrive/i, and what does `/usr/lib/csih/getVolInfo /cygdrive/i'
print(*)? I assume I: is not Samba, right?

Two problems.

- First, the file rename operation in the try_to_bin function fails with
STATUS_INVALID_PARAMETER. try_to_bin is only called if a sharing
violation occured. Obviously I can't tell where the sharing violation
comes from.

I assume that the file system on I: returns this error in place of
another STATUS_SHARING_VIOLATION. But I don't know. I never saw a
STATUS_INVALID_PARAMETER. from the rename function before. The
only other problem I can think of is that the filesystem chokes on
the 64K buffer size of the FILE_RENAME_INFORMATION buffer.

- Second, apparently the actual "Directory not empty" error is generated
artificially by rmdir. There's code which test if the removed directory
still exists after the OS call to remove it. This works around a problem
in Samba, which sometimes doesn't return an error if the directory can't
be removed because it's not empty. For some reason the directory still
exists at that point in time, so you get the error. It's not clear to
me how to workaround this. At least not as long as we have more info about
the filesystem itself.


Corinna

(*) The getVolInfo tool is part of the csih package.
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat
Saurabh T
2010-09-10 23:32:51 UTC
Permalink
Post by Corinna Vinschen
What is that I: drive? What does `mount' print as filesystem type of
/cygdrive/i, and what does `/usr/lib/csih/getVolInfo /cygdrive/i'
print(*)? I assume I: is not Samba, right?
Corinna
mount shows:
I: on /cygdrive/i type cifs (binary,posix=0,user,noumount,auto)
compared to
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
Post by Corinna Vinschen
/usr/lib/csih/getVolInfo /cygdrive/
Device Type : 7
Characteristics : 10
Volume Name : <build>
Serial Number : 110167052
Max Filenamelength : 255
Filesystemname : <NTFS>
Flags : 3
FILE_CASE_SENSITIVE_SEARCH : TRUE
FILE_CASE_PRESERVED_NAMES : TRUE
FILE_UNICODE_ON_DISK : FALSE
FILE_PERSISTENT_ACLS : FALSE
FILE_FILE_COMPRESSION : FALSE
FILE_VOLUME_QUOTAS : FALSE
FILE_SUPPORTS_SPARSE_FILES : FALSE
FILE_SUPPORTS_REPARSE_POINTS: FALSE
FILE_SUPPORTS_REMOTE_STORAGE: FALSE
FILE_VOLUME_IS_COMPRESSED : FALSE
FILE_SUPPORTS_OBJECT_IDS : FALSE
FILE_SUPPORTS_ENCRYPTION : FALSE
FILE_NAMED_STREAMS : FALSE
FILE_READ_ONLY_VOLUME : FALSE
FILE_SEQUENTIAL_WRITE_ONCE : FALSE
FILE_SUPPORTS_TRANSACTIONS : FALSE

I believe I: is Samba (says so in "My Computer").

Thanks,
saurabh
Corinna Vinschen
2010-09-11 10:59:03 UTC
Permalink
Post by Saurabh T
Post by Corinna Vinschen
What is that I: drive? What does `mount' print as filesystem type of
/cygdrive/i, and what does `/usr/lib/csih/getVolInfo /cygdrive/i'
print(*)? I assume I: is not Samba, right?
Corinna
I: on /cygdrive/i type cifs (binary,posix=0,user,noumount,auto)
compared to
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
Post by Corinna Vinschen
/usr/lib/csih/getVolInfo /cygdrive/
Device Type : 7
Characteristics : 10
Volume Name : <build>
Serial Number : 110167052
Max Filenamelength : 255
Filesystemname : <NTFS>
Flags : 3
FILE_CASE_SENSITIVE_SEARCH : TRUE
FILE_CASE_PRESERVED_NAMES : TRUE
FILE_UNICODE_ON_DISK : FALSE
FILE_PERSISTENT_ACLS : FALSE
FILE_FILE_COMPRESSION : FALSE
FILE_VOLUME_QUOTAS : FALSE
FILE_SUPPORTS_SPARSE_FILES : FALSE
FILE_SUPPORTS_REPARSE_POINTS: FALSE
FILE_SUPPORTS_REMOTE_STORAGE: FALSE
FILE_VOLUME_IS_COMPRESSED : FALSE
FILE_SUPPORTS_OBJECT_IDS : FALSE
FILE_SUPPORTS_ENCRYPTION : FALSE
FILE_NAMED_STREAMS : FALSE
FILE_READ_ONLY_VOLUME : FALSE
FILE_SEQUENTIAL_WRITE_ONCE : FALSE
FILE_SUPPORTS_TRANSACTIONS : FALSE
I believe I: is Samba (says so in "My Computer").
I don't think so. It's not recognized as Samba by Cygwin because
the FILE_PERSISTENT_ACLS flag is not set. That should always be
set by Samba when faking an NTFS. However, this gives us potentially
a lever to workaround your problem.

I've checked in a change to rmdir into CVS. Please test your case
with the next developer's snapshot from http://cygwin.com/snapshots/
and report back.


Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat
Continue reading on narkive:
Search results for 'rm -r removes directory but reports "cannot remove 'dir', directory not empty"' (Questions and Answers)
9
replies
How do you execute a file in Unix? I was told #!/bin/sh, but where is this used.?
started 2007-03-16 16:15:32 UTC
programming & design
Loading...