bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#7823: Rm -f fails on non-existant file


From: Nadav Har'El
Subject: bug#7823: Rm -f fails on non-existant file
Date: Tue, 11 Jan 2011 14:58:43 +0200
User-agent: Mutt/1.4.2.2i

Hi,

"rm -f" is supposed to succeed (and not print an error message) when the
given file name does not exist.

Unfortunately, I found a rare case where this is not happening.

It appears that when mounting a Windows filesystem using Samba, if I try
running:
command

        #!/bin/sh
        mkdir emptydir
        rm -f emptydir/*

The shell leaves this "*" unchanged, and rm gives this name to unlink(2),
which oddly enough returns EINVAL (invalid argument) instead of the expected
ENOENT (no such file or directory!).

I'm guessing the smbfs people chose to give this as a special error when
"invalid" characters are used in the file name (this is a concept that doesn't
exist in Unix), but I'm not sure why it was so important to them to not
just return ENOENT in this case... But still, I think "rm" should behave
well in this case.

So currently, in the above example "rm -f emptydir/*", instead of just doing
nothing silently, prints an error message (Invalid Argument) and does exit(1).
This, for example, causes problems in Makefiles which run "rm -f" assuming it
won't fail (yes, I know, make has the "-" modifier - unfortunately some
makefiles don't use it...).

Anyway, in remove.c, you have

static inline bool
nonexistent_file_errno (int errnum)
{
  switch (errnum)
    {
    case ENOENT:
    case ENOTDIR:
      return true;
    default:
      return false;
    }
}

And I wonder whether EINVAL shouldn't also be added to it.

Thanks,
Nadav Har'El.

-- 
Nadav Har'El                        |      Tuesday, Jan 11 2011, 6 Shevat 5771
address@hidden             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Share your knowledge. It's a way to
http://nadav.harel.org.il           |achieve immortality.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]