Re: Locking Files?
Re: Locking Files?
- Subject: Re: Locking Files?
- From: Vince DeMarco <email@hidden>
- Date: Sat, 8 Sep 2001 02:33:38 -0700
On Friday, September 7, 2001, at 02:36 pm, Rosyna wrote:
It requires carbon be used.
NSString* path=alreadyExistingPath;
FSRef theRef;
FSCatalogInfo catInfo;
OSErr err=noErr;
err=FSPathMakeRef([path UTF8String],&theRef,NULL);
// check for err here. noErr==0
err=FSGetCatalogInfo(&theRef,kFSCatInfoNodeFlags,&catInfo,NULL,NULL,NULL)
;
// check for err here.
if ( [locked state] )
catInfo.nodeFlags |= kFSNodeLockedMask;
else
catInfo.nodeFlags &= ~kFSNodeLockedMask;
err=FSSetCatalogInfo(&theRef,kFSCatInfoNodeFlags,&catInfo);
//check for err here.
Ack, at 9/7/01, Josh M. Hurd said:
Is it possible to lock and unlock files in Cocoa? I checked the
NSFileManger docs but it doesn't seem to mention anything about locking
files. I also checked the Functions section for Foundation and AppKit.
Do I have to resort to using Carbon functions? I'd rather not if
possible.
Try looking at chflags()
CHFLAGS(2) System Programmer's Manual
CHFLAGS(2)
NAME
chflags, fchflags - set file flags
SYNOPSIS
#include <sys/stat.h>
#include <unistd.h>
int
chflags(const char *path, u_long flags)
int
fchflags(int fd, u_long flags)
DESCRIPTION
The file whose name is given by path or referenced by the descriptor
fd
has its flags changed to flags.
The flags specified are formed by or'ing the following values
UF_NODUMP Do not dump the file.
UF_IMMUTABLE The file may not be changed.
UF_APPEND The file may only be appended to.
SF_IMMUTABLE The file may not be changed.
SF_APPEND The file may only be appended to.
The ``UF_IMMUTABLE'' and ``UF_APPEND'' flags may be set or unset by
ei-
ther the owner of a file or the super-user.
The ``SF_IMMUTABLE'' and ``SF_APPEND'' flags may only be set or unset
by
the super-user. They may be set at any time, but normally may only be
Carbon does end up calling all of the BSD functions eventually to get its
work done, it kind of has too.
vince