• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Locking Files?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Locking Files?
      • From: Rosyna <email@hidden>
References: 
 >Re: Locking Files? (From: Rosyna <email@hidden>)

  • Prev by Date: Re: Saving window location
  • Next by Date: Re: How to get the Mac OS X version?
  • Previous by thread: Re: Locking Files?
  • Next by thread: Re: Locking Files?
  • Index(es):
    • Date
    • Thread