Re: Bug with Localized Failure Reason and file moving

2015-03-31 Thread Daryle Walker
> On Mar 24, 2015, at 8:44 PM, Daryle Walker  wrote:
> 
> A segment from my command-line tool:
> 
>>NSURL * const  finalLocation = [NSURL 
>> fileURLWithPath:response.suggestedFilename isDirectory:NO];
>> 
>>[[NSFileManager defaultManager] moveItemAtURL:location 
>> toURL:finalLocation error:&error];
>>if (error) {
>>gbfprint(stderr, @"Error, copying: %@", 
>> error.localizedDescription);
>>gbfprintln(stderr, error.localizedFailureReason ? @" 
>> (%@)" : @"", error.localizedFailureReason);
>>returnCode = EXIT_FAILURE;
>>} else {
>>gbprintln(@"%@", finalLocation.path);
>>}
> 
> When I run the tool a second time, with the same URL argument, so it tries 
> moving the temp file to a place where a file already exists, I get:
> 
>> Error, copying: “CFNetworkDownload_8gfN5h.tmp” couldn’t be moved to “Debug” 
>> because an item with the same name already exists. (A file with the name 
>> “CFNetworkDownload_8gfN5h.tmp” already exists.)
>> Program ended with exit code: 1
> 
> The localized failure reason uses the source file name, the real reason is 
> that the DESTINATION file name is the one already in use.
> 
> Am I misunderstanding something here, or should I try to figure out how to 
> send in bug reports to Apple?

I’ll just let Apple figure it out. Reported to their bug reporter with ID 
20367692.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Bug with Localized Failure Reason and file moving

2015-03-30 Thread Daryle Walker
> On Mar 30, 2015, at 3:00 AM, dangerwillrobinsondan...@gmail.com wrote:
> 
>> On 2015/03/25, at 9:44, Daryle Walker  wrote:
>> 
>> A segment from my command-line tool:
>> 
>>>   NSURL * const  finalLocation = [NSURL 
>>> fileURLWithPath:response.suggestedFilename isDirectory:NO];
>>> 
>>>   [[NSFileManager defaultManager] moveItemAtURL:location 
>>> toURL:finalLocation error:&error];
>>>   if (error) {
>>>   gbfprint(stderr, @"Error, copying: %@", 
>>> error.localizedDescription);
>>>   gbfprintln(stderr, error.localizedFailureReason ? @" 
>>> (%@)" : @"", error.localizedFailureReason);
>>>   returnCode = EXIT_FAILURE;
>>>   } else {
>>>   gbprintln(@"%@", finalLocation.path);
>>>   }
>> 
>> When I run the tool a second time, with the same URL argument, so it tries 
>> moving the temp file to a place where a file already exists, I get:
>> 
>>> Error, copying: “CFNetworkDownload_8gfN5h.tmp” couldn’t be moved to “Debug” 
>>> because an item with the same name already exists. (A file with the name 
>>> “CFNetworkDownload_8gfN5h.tmp” already exists.)
>>> Program ended with exit code: 1
>> 
>> The localized failure reason uses the source file name, the real reason is 
>> that the DESTINATION file name is the one already in use.
>> 
>> Am I misunderstanding something here, or should I try to figure out how to 
>> send in bug reports to Apple?
>> 
>> — 
> The message is correct. 
> In the view of the underlying POSIX API a file exists already with that name 
> at that path. 
> If your file name is too simplistic you're going to struggle. 
> You need to determine your move policy. File names can be unique with simple 
> things like timestamps or UUIDs which are easy to create. 
> You need to decide whether to unique them (proactively avoid collisions) or 
> handle collisions and how. 
> You could replace it or append.

There’s already a file with that name at the DESTINATION path. (Except for the 
runs where I erase it first, of course. But there’s no error in those runs.) 
The error message uses the SOURCE path at both file-name instances, when it 
should be the source filename at the first mention (localized description) and 
the destination filename at the second mention (localized failure reason). 
(“Debug” is the directory containing the destination filename.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Bug with Localized Failure Reason and file moving

2015-03-30 Thread dangerwillrobinsondanger


> On 2015/03/25, at 9:44, Daryle Walker  wrote:
> 
> A segment from my command-line tool:
> 
>>NSURL * const  finalLocation = [NSURL 
>> fileURLWithPath:response.suggestedFilename isDirectory:NO];
>> 
>>[[NSFileManager defaultManager] moveItemAtURL:location 
>> toURL:finalLocation error:&error];
>>if (error) {
>>gbfprint(stderr, @"Error, copying: %@", 
>> error.localizedDescription);
>>gbfprintln(stderr, error.localizedFailureReason ? @" 
>> (%@)" : @"", error.localizedFailureReason);
>>returnCode = EXIT_FAILURE;
>>} else {
>>gbprintln(@"%@", finalLocation.path);
>>}
> 
> When I run the tool a second time, with the same URL argument, so it tries 
> moving the temp file to a place where a file already exists, I get:
> 
>> Error, copying: “CFNetworkDownload_8gfN5h.tmp” couldn’t be moved to “Debug” 
>> because an item with the same name already exists. (A file with the name 
>> “CFNetworkDownload_8gfN5h.tmp” already exists.)
>> Program ended with exit code: 1
> 
> The localized failure reason uses the source file name, the real reason is 
> that the DESTINATION file name is the one already in use.
> 
> Am I misunderstanding something here, or should I try to figure out how to 
> send in bug reports to Apple?
> 
> ― 
The message is correct. 
In the view of the underlying POSIX API a file exists already with that name at 
that path. 
If your file name is too simplistic you're going to struggle. 
You need to determine your move policy. File names can be unique with simple 
things like timestamps or UUIDs which are easy to create. 
You need to decide whether to unique them (proactively avoid collisions) or 
handle collisions and how. 
You could replace it or append. 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Bug with Localized Failure Reason and file moving

2015-03-29 Thread Daryle Walker
On Mar 24, 2015, at 8:56 PM, Quincey Morris 
 wrote:
> 
> On Mar 24, 2015, at 17:44 , Daryle Walker  > wrote:
>> 
>>[[NSFileManager defaultManager] moveItemAtURL:location 
>> toURL:finalLocation error:&error];
>>if (error) {
> 
> Your code is wrong. You must test the return value of ‘moveItemAtURL:’ for 
> success or failure. Only if the result is NO (failure) is the error valid.
> 
> In this case, the move is likely succeeding, and the error parameter doesn’t 
> contain a meaningful error.

Making this change doesn’t change the error message. (As I expected, since 
getting the test wrong doesn’t change the fact that the file from the previous 
run is blocking putting another there.) I guess I need to file a bug on how the 
error message is generated.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Bug with Localized Failure Reason and file moving

2015-03-24 Thread Quincey Morris
On Mar 24, 2015, at 17:44 , Daryle Walker  wrote:
> 
>[[NSFileManager defaultManager] moveItemAtURL:location 
> toURL:finalLocation error:&error];
>if (error) {

Your code is wrong. You must test the return value of ‘moveItemAtURL:’ for 
success or failure. Only if the result is NO (failure) is the error valid.

In this case, the move is likely succeeding, and the error parameter doesn’t 
contain a meaningful error.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com