Determining if a file is located in the trash from a daemon problem - Getting nsvErr
Determining if a file is located in the trash from a daemon problem - Getting nsvErr
- Subject: Determining if a file is located in the trash from a daemon problem - Getting nsvErr
- From: Jean-Francois Dontigny <email@hidden>
- Date: Fri, 18 Sep 2009 16:21:07 -0400
- Thread-topic: Determining if a file is located in the trash from a daemon problem - Getting nsvErr
Hello list!
I would like to determine if a directory is contained in the trash before
doing some file operations. To do that, I have tried to use the
FSDetermineIfRefIsEnclosedByFolder() function. For some reason, I cannot get
the function to work. I always get a nsvErr, and the output flag is never
set. I am completely at a lost as to why.
I know my FSRef is ok, as I am able to convert it back to a path. I have
tried to pass in different options, such as kOnAppropriateDisk,
kOnSystemDisk and 0 for the domain, and kTrashFolderType and
kSystemTrashFolderType for the folder type, to no avail.
Whether or not the directory is in the trash, I get an nsvErr, and the
boolean is set to false.
Here is the code:
- (NSString *)pathFromCNID:(NSNumber *)pathCNID
volumeId:(NSNumber *)volumeId
{
FSRef fileRef;
UInt8 filePath[255];
Boolean isInTrash = NO;
OSStatus error = FSResolveNodeID([volumeId shortValue],
[pathCNID intValue],
&fileRef);
if (error) {
log4Error(@"Could not resolve node id: %s",
GetMacOSStatusErrorString(error));
return nil;
}
error = FSRefMakePath(&fileRef, filePath, 255);
if (error) {
log4Error(@"Could not convert reference to path: %s",
GetMacOSStatusErrorString(error));
return nil;
}
// We do not want to resolve if the parent directory has been moved to
the trash
error = FSDetermineIfRefIsEnclosedByFolder(0,
kTrashFolderType,
&fileRef,
&isInTrash);
log4Error(@" isInTrash: %s", (isInTrash ? @"YES" : @"NO"));
if (error) {
log4Error(@"Could not verify if the path %s is in the trash: %s",
filePath,
GetMacOSStatusErrorString(error));
return nil;
} else if (isInTrash) {
return nil;
}
return [NSString stringWithUTF8String:(const char *)filePath];
}
Here is the output in the log:
2009/09/18 15:55:00 ERROR -[RPFileHelp pathFromCNID:volumeId:] <> -
isInTrash: NO
2009/09/18 15:55:00 ERROR -[RPFileHelp pathFromCNID:volumeId:] <> - Could
not verify if the path /Users/jeand/.Trash/dossier sans titre 14-48-48 is in
the trash: nsvErr
And here is the stat output of the directory in the trash:
stat ~/.Trash/dossier\ sans\ titre\ 14-48-48
234881026 129266021 drwxr-xr-x 6 jeand wheel 0 204 "Sep 18 16:17:48 2009"
"Sep 18 15:15:12 2009" "Sep 18 15:15:12 2009" "Sep 18 14:18:33 2009" 4096 0
0 /Users/jeand/.Trash/dossier sans titre 14-48-48
Can anyone explain why I keep getting the nsvErr? Is it possible that I
cannot use this function as root? (the code is running inside a daemon)
Any insight would be appreciated.
Regards,
Jean-Francois Dontigny
***********************************************************************
This e-mail and its attachments are confidential, legally privileged, may be subject to copyright and sent solely for the attention of the addressee(s).
Any unauthorized use or disclosure is prohibited. Statements and opinions expressed in this e-mail may not represent those of Radialpoint.
Le contenu de ce courriel est confidentiel, privilégié et peut être soumis à des droits d'auteur. Il est envoyé à l'intention exclusive de son ou de ses
destinataires. Il est interdit de l'utiliser ou de le divulguer sans autorisation. Les opinions exprimées dans le présent courriel peuvent diverger de celles de Radialpoint.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden