ENOENT is returned only if
harp:~ > man 2 link
...
SYNOPSIS
#include <unistd.h>
int link(const char *oldpath, const char *newpath);
...
ENOENT A directory component in oldpath or newpath does not exist or
is a dangling symbolic link.
otherwise ENOEXIST is returned as this shows
harp:~ > cat a.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
main (int argc, char **argv)
{
char command[256];
link (argv[1], argv[2]);
sprintf (command, "ruby -e'p(SystemCallError::new(%d))'", errno);
system(command);
}
harp:~ > gcc a.c
harp:~ > ls foo
ls: foo: No such file or directory
harp:~ > ls bar
ls: bar: No such file or directory
harp:~ > a.out foo bar
#<Errno::ENOENT: No such file or directory>
ENOENT is returned if we are dealing with bad directories only
harp:~ > a.out /no/such/path/foo bar
#<Errno::ENOENT: No such file or directory>
harp:~ > a.out foo /no/such/path/bar
#<Errno::ENOENT: No such file or directory>
but two good dirs always result in ENOEXIST
harp:~ > a.out /usr/foo /usr/bar
#<Errno::ENOENT: No such file or directory>
and a subsequent stat to determine which pathname did not exist would be a
race condition so i think you are stuck with this.
cheers.
-a
···
On Sun, 12 Jun 2005, a slow loris wrote:
Why does File.link() report that the source file exists? It really
ought to only report that the destination file exists. It isn't an
error for the source to exist. If it didn't, we'd get ENOENT, not
EEXIST.
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
My religion is very simple. My religion is kindness.
--Tenzin Gyatso
===============================================================================