1

Is there a difference between

NSURL *referenceURL, *destinationURL ;

[[[NSFileManager alloc] init] copyItemAtURL:referenceURL
                                      toURL:destinationURL
                                      error:NULL] ;

and

NSURL *referenceURL, *destinationURL ;
NSFileWrapperWritingOptions options ;

NSFileWrapper * fileWrapper = [[NSFileWrapper alloc] initWithURL:referenceURL
                                                         options:0
                                                           error:NULL] ;
[fileWrapper writeToURL:destinationURL
                options:options
    originalContentsURL:nil
                  error:NULL] ;

(especially, depending on the values of options; what would be the best choice for options here?)?

I ask this question in order to understand better NSFileWrapper. I see that I have the choice in my code to use one or the other. I guess the answer might involve considerations about "hard links".

PS: I would like to use any of these methods in background.

Colas
  • 3,473
  • 4
  • 29
  • 68

1 Answers1

1

For using it in the background use NSThread to create a (second or more) thread beneath the mainThread.

I have not worked with an NSFileWrapper, but a lot with NSFileManager. Which one to use, depends on, what (and how) you want your app to work with files/folders/links.

In anyway do I have some suggestions for you after reading the documentation:

The FM works with the textual path/URL of a file, folder, link. When copying an application(-file) with FM, it often fails, because an application is not a file, but a special type of folder = file package, that often contain files/folders with restricted rights for reading or writing. Copying a folder with its content will lead to a change in the change date of this folder, because the folder is created first and then its content changed! Maybe you do not want that change.

The FW works with nodes (what could be seen as a kind of container with infos and other data about an object in the filesystem), that belongs to a given path/URL. Once the FW is created, the path may change, but the FW still has access to the file, folder, link. It also saves space on your disk and time, that if a copied object, that has not changed, is only hard-linked in a node instead of really copying the whole file again.

The writing option "NSFileWrapperWritingAtomic" assures, that a file package is really completely copied, instead of an interrrupted copy-process as with FM happens. Then you have an incomplete file package, without knowing, when the process stopped. I guess(!), that it is possible, to copy application completely, independent from the r/w rights of the contained files/folders OR it's possible to change these rights temporarily to complete the task.

macrene
  • 198
  • 1
  • 8
  • Can you explain more the "hard links" thing? It is very unclear for me. Thanks. – Colas Mar 28 '14 at 11:48
  • A hard link in UNIX is a link to a file/not a directory. It enables you to give a file a second filename in the same or another directory, without having to copy or move the file and is created by adding an entry in a directory, using "ln" in UNIX. Hard links cannot cross file system boundaries. The new name can be a relative or an absolute pathname. – macrene Mar 31 '14 at 12:19