Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any difference between ios file:///var/mobile/Containers and file:///private/var/mobile/Containers?

Tags:

ios

swift

Are they different or simple aliases?

I obtain the /private/var by running:

FileManager.default.contentsOfDirectory(at: folder, includingPropertiesForKeys: [], options: [])

And the second is created with a simple:

data.write(to: f, options: [.atomic]) 

where f is in the same directory as "folder"

like image 882
Stéphane de Luca Avatar asked Mar 20 '18 18:03

Stéphane de Luca


People also ask

What is private var mobile containers?

From The iPhone Wiki. /private/var/mobile is a folder in the iOS filesystem. Inside it, the (root)/private/var/containers/Bundle/Application folder contains some app store apps, though others may be located in .

What is var mobile?

The Veteran Appointment Request (VAR) mobile application (app) allows Veterans who are in the Department of Veterans Affairs (VA) health care system to self-schedule and request primary care appointments.


2 Answers

That are the same directories, as one can verify by retrieving the “canonical path” for both:

let url1 = URL(fileURLWithPath: "/var/mobile/Containers/")
if let cp = (try? url1.resourceValues(forKeys: [.canonicalPathKey]))?.canonicalPath {
    print(cp)
    // "/private/var/mobile/Containers"

}
let url2 = URL(fileURLWithPath: "/private/var/mobile/Containers/")
if let cp = (try? url2.resourceValues(forKeys: [.canonicalPathKey]))?.canonicalPath {
    print(cp)
    // "/private/var/mobile/Containers"
}

In fact, /var is a symbolic link to /private/var:

var buffer = Array<Int8>(repeating: 0, count: 1024)
if readlink("/var", &buffer, buffer.count) > 0 {
    print(String(cString: &buffer))
    // "private/var"
}
like image 174
Martin R Avatar answered Oct 19 '22 14:10

Martin R


For Swift users, using URL.standardizedFileURL eliminates the ambiguity/confusion caused by paths which contain soft links or other different elements that ultimately resolve to the same file.

like image 41
biomiker Avatar answered Oct 19 '22 15:10

biomiker