[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible bug in NSFileManager
From: |
e.sammer |
Subject: |
Re: Possible bug in NSFileManager |
Date: |
Sat, 09 Mar 2002 02:48:42 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020204 |
Richard Frith-Macdonald wrote:
On Saturday, March 9, 2002, at 12:20 AM, e.sammer wrote:
I assume you mean in [copyPath:toPath:handler:] (there is no copyFile:
method) ... it should work there.
As far as I can see from quick look over the code, it should honor the
documentation to the letter -
but the documentation is not completely unambiguous :-(
in reading the mosx api reference, states the following:
"Copies the directory or file specified in path source to a different
location in the file system identified by path destination. If source is
a file, the method creates a file at destination that holds the exact
contents of the original file (this includes BSD special files). If
source is a directory, the method creates a new directory at destination
and recursively populates it with duplicates of the files and
directories contained in source, preserving all links. The file
specified in source must exist, while destination must not exist prior
to the operation. When a file is being copied, the destination path must
end in a file name-there is no implicit adoption of the source file
name. Symbolic links are not traversed but are themselves copied."
(the above is taken from the first paragraph of copyPath:toPath:handler:
in NSFileManager at apple's dev site)
the way i read it was that sym links were copied to the destination path
and underwent no additional traversal (as per the last line). of course,
i could be wrong.
i can't seem to find a copy of the OpenStep spec anywhere online (thanks
Sun / Apple) so i couldn't check it for reference. i thought there was a
link somewhere on the GS site, but i can't find that either.
Could you provide a small test program to demonstrate your problem.
at the bottom is a quick tool that shows the error. use it to try and
copy a link to a file or a link to a directory.
While the code seems to conform to the letter of the documentation, I'm
not at all sure it does the
most intuitive/useful thing. It seems to be preserving the original
symbolic links - but I'd have
thought it made more sense, if a link pointed to somewhere within the
path being copied, for the
new symbolic link to be made to the appropriate location within the
copied structure.
i might be missing what you're saying here... if you're saying it would
make more sense for me to copy the real file and then just make a new
link, it's possible, but certainly not convienient. the method of
retrieving the file pointed to by a link seems unreliable (if i recall)
if at all possible. i'm sure it's one of many solutions... just not too
comfortable with that one.
I guess few people use them, and thus no comparison between actual
MacOS-X behavior and GNUstep
behavior has been made.
understandable. like i said, i only found this because i'm doing a large
amount of copy / remove / link work with NSFileManager. most of the
time, i think most of us just use fileExistsAtPath:isDirectory: and call
it a day. :)
I'd be very happy to apply patches to fix this
to provide the same
real (as opposed to documented) behavior
i'm not sure what you mean by real vs. documented behavior. i was under
the impression that the real behavior was the documented behavior.
- as long as the real MacOS-X
behavior is not clearly
a bug of course.
again, as i read the docs, it seemed clear as to what the intended
behavior is or was supposed to be.
here's a quick tool to demonstrate the problem. it takes two (completely
unchecked) args - first one source file, second one dest file. on my
box, if source is a link to a file, it copies the file AND set the
permissions of the link to the file (potential MASSIVE security
problem). if the link points to a directory, it just recursively copies
the directory and its contents.
thanks for the response...
-------------- BEGIN -------------------------
#include <Foundation/Foundation.h>
int main(int argc, const char* argv[])
{
NSAutoreleasePool* pool;
NSFileManager* fm;
pool = [[NSAutoreleasePool alloc] init];
fm = [NSFileManager defaultManager];
if (argc == 3) {
[fm copyPath:[NSString stringWithCString:argv[1]]
toPath:[NSString stringWithCString:argv[2]]
handler:nil];
} else {
printf("Usage: %s <source> <dest>\n\n", argv[0]);
}
[pool release];
}
--------------- END ----------------------
--
e.sammer <eric@lifeless.net>
"...and if i could kill without guilt or sin..." - MOLG