Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple File Copy



And actually I had sort of a tangential question to this one:

I need to make a backup of /private/etc/hosts, modify the hosts file, then restore the backup to the hosts file when I am done. Currently I do this through a privileged helper tool. My strategy is to use FSpExchangeFiles or FSExchangeObjects to simply swap the data in the two files when it comes time to do my restore.

Everything works fine except for one little problem - any write access to the /private/etc/hosts file fails with a File Manager permissions error. I can read and copy the hosts file with no problem, but when I try to write to it, or even open it with write permission, I get the permission error. FSpOpenDF, FSpExchangeFiles, and FSExchangeObjects all return the same error. It makes no difference whether I try to open the file first or not.

I realize /private/etc/hosts is a protected system file, but I am calling my code to swap the contents of the two files from within my helper tool in privileged mode. I would expect it to work from within that context as my other privileged operations do. And I can edit the /private/etc/hosts file manually if I authorize first.

Do I need to manually chmod the /private/etc/hosts file first or something before I attempt a write operation to it? Why can't the write operation work from within a privileged, authorized context?

Thanks,

Michael Amorose
Orbital Launch & Lift, Inc.
http://www.orbitallaunch.com

At 11:35 AM -0800 11/18/04, Eric Schlegel wrote:
On Nov 18, 2004, at 10:10 AM, Laurence Harris wrote:

As for seeing what's needed, full-featured, robust file copying is no small
undertaking on the Mac. Multiple forks, drop boxes, Finder comments,
recursion into folders, and meta data all need to be addressed and frankly,
it's a lot easier for a newbie to just to use FSCopyObject than it is to try
to understand everything FSCopyObject is doing.

If you really need to write your own file copying code, unfortunately you
have to choose between looking at MoreFiles, which is out of date, or
FSCopyObject, which IMO is over-engineered and harder to follow.

For those of you with Tiger seeds, you may wish to look at Files.h and search for "FSCopyObject".


-eric

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Simple File Copy (From: Laurence Harris <email@hidden>)
 >Re: Simple File Copy (From: Eric Schlegel <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.