Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FSPathMakeRef and FSRefMakePath are deprecated in OS X 10.8, what are the alternatives?

I've noticed that FSPathMakeRef() and FSRefMakePath() are now deprecated in OS X 10.8.

I have some code that uses them to find the canonical case for a path, e.g. if passed "/USeRs" it will return "/Users".

Why have these and other related functions been deprecated, and what non-deprecated API should be used now instead to provide equivalent functionality?

like image 513
Richard Viney Avatar asked Jul 29 '12 12:07

Richard Viney


1 Answers

Use NSURL to store both ordinary paths and file reference paths.

From the File Manager documentation (Appendix A: Deprecated File Manager Functions):

FSMakeFSRefUnicode

Constructs an FSRef for a file or directory, given a parent directory and a Unicode name. (Deprecated in OS X v10.8. Use NSURL or CFURL APIs instead. To track the behavior of file-system items by ID, create file reference URLs using fileReferenceURL or CFURLCreateFileReferenceURL.)

From what I can tell, Apple chose to deprecate the FSRef type entirely, favouring file reference URLs (which look like file:///.file/id=6571367.39068/) instead.

If you want to canonicalize a string path, you can do the following using non-deprecated APIs:

NSString *canonicalPath = [[[NSURL fileURLWithPath:@"/USeRs"] fileReferenceURL] path];
like image 108
nneonneo Avatar answered Sep 25 '22 05:09

nneonneo