I'm trying to port some code to new Carbon API... And working on
function which can set ReadOnly file attirbute.
In old code I had somesing like this to reset ReadOnly attribute:
error = HRstFLock(fsSpec.vRefNum, fsSpec.parID,
_CtoPstr(thetext));
error = FSpRstFLock(&fsSpec);
I'm not sure that this code worked fine...
Currentrly I'm learning FSSetCatalogInfo function and don't know what
should I do...
This code doesn't work:
HFSUniStr255 outName;
FSSpec fsSpec;
FSRef parentRef;
FSCatalogInfo catalogInfo;
error = FSGetCatalogInfo(&fsRefFile, NULL, &catalogInfo, &outName,
&fsSpec, &parentRef);
if ( catalogInfo.nodeFlags & kFSNodeLockedMask)
{
UInt16 uiFlagMask = kFSNodeLockedMask;
uiFlagMask = ~uiFlagMask;
catalogInfo.nodeFlags = catalogInfo.nodeFlags & (uiFlagMask); //
Turn off flag
error = FSSetCatalogInfo( &fsRefFile, NULL, (const
FSCatalogInfo*)&catalogInfo);
}
I'm using finder, and it show that file is still ReadOnly...
That bit controls the [] Locked checkbox, high in the Finder's Info
window. To control the "read only" popup, low in the window, you must
use some equivalent of chmod() from the System framework, which takes a
POSIX path.
FSSetCatalogInfo can also change the permissions. The FSCatalogInfo
structure has a permissions field that can be interpreted as a
FSPermissionInfo structure. You'd want the kFSCatInfoPermissions flag in
the whichInfo argument.
Um. Now that I look at it, one major reason that the above code isn't
working would be that you're passing 0 for that argument in both the Get
and Set functions.
1.) It's look like that chmod works fine.
2.) And what about FSCatalogInfo, "permissions" field - represent
FSPermissionInfo struct. I think it's better to copy from
"permissions" into local variable of type FSPermissionInfo, and than
change it, and copy back...
In FSPermissionInfo I should change mode fileld, as in chmod function?
What is the best way, and more safely???
Thanks!