Nexus 7, Android 4.3: Same directory, two canonical paths
Asked Answered
B

0

6

I'm using a Nexus 7 running Android 4.3. Two directory paths on this device are confusing me:

/storage/emulated/legacy
/storage/emulated/0

If I call new File(<path>).getCanonicalPath() for either of these, I get the same path back. If I call the C function realpath with either, it succeeds and returns the same path. So it sounds like each of these is its own canonical path, and therefore they are different directories.

However, If I create a subdirectory in either one, that subdirectory also appears in the other. That gives me the impression that they are two paths to the same directory.

Is there a better way to tell that these paths are really for the same directory?

Backsaw answered 28/9, 2013 at 16:28 Comment(6)
Why does it matter? After all, you shouldn't be using either of those directories literally. For example, your app may not have access to them, because your app is running in a secondary user account or restricted profile.Spinoff
Good question. When file I/O is performed, I want to tell whether it's happening in the so-called external storage directory. I can get that path by calling Environment.getExternalStorageDirectory, but that covers only one of these paths.Backsaw
"When file I/O is performed" -- if you are the one doing the file I/O, you know whether you are using internal or external storage.Spinoff
True. In this case, I'm not always the one doing the file I/O. This is for something that integrates with third-party apps.Backsaw
There is another time when this information would be useful -- recursing through directories looking for files. It would be good to tell that these are the same directory so that the same files are not added multiple times.Backsaw
Another use case, needed to run a tool via the shell on a path. /storage/emulated/0 is not even a real path on my device, but it's what Android returns and works in the Java code.Oh

© 2022 - 2024 — McMap. All rights reserved.