Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / December 2006



Tip: Looking for answers? Try searching our database.

copy wihout resource fork

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick Machielse - 28 Dec 2006 15:35 GMT
I have an application which (amongst other things) copies files to other
devices. Resource files should _not_ be copied (i.e. no ._myfile.ext).

Until now, I've been using cp from an NSTask to perform the copy (this
is instantiated from a separate thread). Obviously, as of 10.4 this will
copy resource forks as well, which isn't what I want. There seems to be
no flag to switch this off. (Thanks stupid cp man page! You don't even
mention resource copying...)

My question: is there a different command line tool (not part of the dev
tools) that can perform a 'naked' file copy, or is there an undocumented
flag to cp that disables res.forks?

Alternatively, I'm looking at 'post-processing' the copy, or writing my
own copy routine/tool.

patrick
Clark S. Cox III - 28 Dec 2006 11:05 GMT
> I have an application which (amongst other things) copies files to other
> devices. Resource files should _not_ be copied (i.e. no ._myfile.ext).
[quoted text clipped - 11 lines]
> Alternatively, I'm looking at 'post-processing' the copy, or writing my
> own copy routine/tool.

How about:

ditto --norsrc

Signature

Clark S. Cox III
clarkcox3@gmail.com

Patrick Machielse - 28 Dec 2006 19:02 GMT
> > My question: is there a different command line tool (not part of the dev
> > tools) that can perform a 'naked' file copy, or is there an undocumented
[quoted text clipped - 3 lines]
>
> ditto --norsrc

This seems like a promising candidate. I've never really used it before,
so it didn't immediately spring to mind (and since it's not referenced
in the cp man page, I didn't find it. I think there's a theme here...)

ditto doesn't support all the cp options I use, but I think it may be
'good enough'.

thanks,

patrick
Reinder Verlinde - 28 Dec 2006 16:15 GMT
> I have an application which (amongst other things) copies files to other
> devices. Resource files should _not_ be copied (i.e. no ._myfile.ext).
[quoted text clipped - 7 lines]
> My question: is there a different command line tool (not part of the dev
> tools) that can perform a 'naked' file copy,

I do not know whether they are or are not part of the dev tools, but

   cat source_path > destination_path

or
   ditto --norsrc source_path destination_path

should work.

> or is there an undocumented flag to cp that disables res.forks?

I do not know about undocumented ones, but "man 5 compat" might be of
help.

> Alternatively, I'm looking at 'post-processing' the copy, or writing my
> own copy routine/tool.

Writing your own is a stupid idea, given that the source for the 10.3
version of cp is available
(<http://www.opensource.apple.com/darwinsource/10.3.9/>)

Reinder
Clark S. Cox III - 28 Dec 2006 12:47 GMT
>> I have an application which (amongst other things) copies files to other
>> devices. Resource files should _not_ be copied (i.e. no ._myfile.ext).
[quoted text clipped - 11 lines]
>
>     cat source_path > destination_path

cat is probably a bad idea, as you will lose meta-data such as
permissions, user/group, etc.

Signature

Clark S. Cox III
clarkcox3@gmail.com

Patrick Machielse - 28 Dec 2006 19:02 GMT
> > or is there an undocumented flag to cp that disables res.forks?
>
> I do not know about undocumented ones, but "man 5 compat" might be of
> help.

Interesting pointer. This could work, but the LEGACY section of man cp
doesn't indicate that it will restore resource fork stripping. The only
way to find out is to try, I guess.

> > Alternatively, I'm looking at 'post-processing' the copy, or writing my
> > own copy routine/tool.
>
> Writing your own is a stupid idea, given that the source for the 10.3
> version of cp is available
> (<http://www.opensource.apple.com/darwinsource/10.3.9/>)

True, I always forget about that. Stupid me! ;-) Still, I'd only do this
as a last resort.

patrick
Patrick Machielse - 29 Dec 2006 15:54 GMT
> > > or is there an undocumented flag to cp that disables res.forks?
> >
[quoted text clipped - 4 lines]
> doesn't indicate that it will restore resource fork stripping. The only
> way to find out is to try, I guess.

A quick test reveals that setting the environment variable COMMAND_MODE
to 'legacy' does not revert cp to the 10.3 behavior of stripping
resource forks. Alas.

patrick
David C. - 28 Dec 2006 17:04 GMT
> My question: is there a different command line tool (not part of the dev
> tools) that can perform a 'naked' file copy, or is there an undocumented
> flag to cp that disables res.forks?

If you're doing the copy from within your application, why not just do
this:

       FILE *in = fopen(infilename, "rb");
       FILE *out = fopen(outfilename, "wb);

       char buffer[1000];
       size_t count;

       while ((count = fread(buffer, 1, 1000, in)) != 0)
       {
           fwrite(buffer, 1, count, out);
       }

       fclose(out);
       fclose(in);

Add some error-checking lines to make this useable in an actual
application and you should be done.  It definitely won't go copying any
resource forke.

-- David
Patrick Machielse - 28 Dec 2006 19:02 GMT
> If you're doing the copy from within your application, why not just do
> this:
[quoted text clipped - 16 lines]
> application and you should be done.  It definitely won't go copying any
> resource forke.

Yeah, but I'm trying to be as lazy as possible here, so if there's a
shortcut available through a standard tool I'll gladly take it ;-)

Also, there's always a heap of details to consider if it must be robust,
and re-inventing the wheel here makes me look stupid (see other
reply..).

patrick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.