Mounted Volume FolderItem does not report the .Parent properly?

If I look at a Mounted USB fob (as an example) that is mounted as “/Volumes/BMD-MAC”, why can’t I get “/Volumes” as the .Parent.NativePath?

For instance, This returns a valid FolderItem of BMD-MAC: or /Volumes/BMD-MAC as the NativePath.

f = GetFolderItem(DiskSource, FolderItem.PathTypeNative)

However, using that returned folder item “f”, this causes a NOE:

SourceParent = f.Parent.NativePath

Shouldn’t SourceParent be “/Volumes” in this case?

19r1.1, 19r3.1 on macOS 10.13

Isn’t the correct question “What is /Volumes” ?

Is is something that exists per se or just a virtual object use to display the on line (connected) mass storage hardware ?

Sorry, I am not sure I was able to define what I had in mind.

Suppose you have Macintosh HD 1, Macintosh HD 2 and Macintosh HD 3 (or a HDD, a SSD and a Micro SD Card): the parents for all theose objects are “/Volumes”.

That is the question - and I just realized that a mounted volume is a “special” entity on the Mac. So, even though the “mountpoint” is /Volumes/MyVolumeName", the FolderItem lists the Parent as Nil. That is just wrong. I understand that “that’s the way it’s always been”, but that doesn’t make it correct. And, the POSIX layer also says that it’s incorrect since it returns the full /Volumes/BMD-MAC path as the pat and /Volumes as the parent …

So, now I have yet another example of #if#endif code to handle yet another Macism. Oh Joy!

so originally is disksource “/Volumes/BMD-MAC” ?

and then after that f.parent is nil ?
that does seem really bizarre

but I can reproduce that here with one of my volumes mounted under /Volumes

I’d file a bug report as that mount point can be accessed as

Dim volumes As folderitem = GetFolderItem("/Volumes", FolderItem.PathTypeNative)

but you cant get at it if you use a mounted volumes parent

EDIT in my case I would expect volumes and vmsparent to refer to the same point but they do not
vmsparent is nil volumes is not

Dim volumes As folderitem = GetFolderItem("/Volumes", FolderItem.PathTypeNative)
Dim vms As folderitem = GetFolderItem("/Volumes/backup1", FolderItem.PathTypeNative)
Dim vmsparent As folderitem = vms.Parent

So, if you have:
/Volumes/Boot
/Volumes/Data
/Volumes/Photos

all of these are individual hard disk (mass storage devices). What will be /Volumes ?
A single object (the same for each device) or three different objects ?
I bet one beer on the former.

If you look at it via the filesystem, you’ll see that /Volumes is a folder - nothing special about it. aside from the fact that it’s hidden.

ls -ledO /Volumes drwxr-xr-x@ 8 root wheel hidden 256 Mar 6 07:47 /Volumes 0: group:everyone deny add_file,add_subdirectory,directory_inherit,only_inherit

As Norman said, it’s an inconsistency in the manner in which Xojo’s FolderItem handles it.

However, it’s been that way all the way back to 12r2.1, so a bug report is probably a bit late at this point.

OK. Sorry for the wrong hypothesis.

:smiley:

I’d still file the report either way since its inconsistent
I’d expect this code to print “they are the same”

Dim volumes As folderitem = GetFolderItem("/Volumes", FolderItem.PathTypeNative)
Dim vms As folderitem = GetFolderItem("/Volumes/backup1", FolderItem.PathTypeNative)
Dim vmsparent As folderitem = vms.Parent

if vmsparent is volumes then
   msbbox  "they are the same"
end if

and the code itself isnt obviously wrong in any way that I can see so I dont think the expectation is wrong

And that’s part of the problem… there are many projects out there that rely on this behavior.
It is kind of both right and wrong - I agree with that.

Let’s look at the docs… FolderItem.Parent

And let’s look at the User Guide: File Access

The User Guide seems to confirm this as an “expected behavior” (Parent of a Volume is always “nil”). By design - even if this is irritating on those OSes where Volumes are being mounted into a moint point, and there is only a single “root”.

From a x-platform point of view, it kind of makes sense. From the macOS/Linux FileSystem, not always so much.

If someone is going to report that… please mention that a change likely breaks existing code that relies on this “documented” behavior.

Maybe it would make sense to have a “.Parent” behave like it always has (and document it more clearly).
And to introduce a new “.TrueParent” (thinking API 1). Or a “.Parent(stopAtMountPoint As Boolean = true)”.
Oh, and another Property “.IsVolume” (*) would be nice to have, too…

i That’s what I’ve seen in more than one project, example code or advice…: just check if the .Parent=nil… so that’s why changing this behavior is likely breaking existing code…[/i]

That

Dim volumes As folderitem = GetFolderItem("/Volumes", FolderItem.PathTypeNative)

gives you a valid folderitem is curios as it doesnt fit with the rest of the docs
Plus it isnt trying to access “the root” (that would be /)
Nor is

Dim vms As folderitem = GetFolderItem("/Volumes/backup1", FolderItem.PathTypeNative)
Dim vmsparent As folderitem = vms.Parent

access the root (again that would be /)

Theres “something” funky about how its inconsistent and to me it seems that

Dim vmsparent As folderitem = vms.Parent

setting vmsparent to nil is somehow the culprit

As for accessing volumes and getting their folderitem thats what the Volume / Folderitem.DriveAt functions do

Although since Unix can mount a volume at any point I wonder if this works properly if someone manually mounts a drive at a weird mount point and NOT in /Volumes
Suppose a person mounts a drive at ~/SomeNewDrive and does that show up in the items returned by Volume / Folderitem.DriveAt ?

[quote=478216:@Norman Palardy]Although since Unix can mount a volume at any point I wonder if this works properly if someone manually mounts a drive at a weird mount point and NOT in /Volumes
[/quote]
Yes, it does as we mount our big volume shares under /mnt/ in the same manner that we mount them on Linux, Solaris, FreeBSD, A/IX, and HP-UX, and I see normal functionality for these volumes on macOS and Linux (/mnt is reported as the parent), unlike the issue - which ONLY occurs with the macOS automounting devices under /Volumes. Windows, in these cases, is it’s own herd of wild cats …

and there’s that danged EDS commercial running through my head again :slight_smile:

Yes, it does. At home, I have my NAS shares mounted here: /Users/username/Library/Family/sharename
DriveCount, DriveAt recognize them.

And guess what the FolderItem.Parent’s of my mounted NAS shares are…? nil. All of them. With 2019r3.1, 2018r4, and ever since. It’s not just when mounted in /Volumes.

@Tim Jones: 19r1.1, 19r3.1 on macOS 10.13

I can’t recall I had problems with 19r1.1. I noticed the problem with the advent of 19r2.

I had pieces of code like:

if f.parent = nil then//or something similar

So I have changed them into:

if f.isVolume then
//do something
end if

Using macOSLib:

[code]#if targetMacOS
dim url as new NSURL( theVolume )
dim nsn as new NSNumber( url.ResourceValuePtr( url.NSURLIsVolumeKey))

return nsn.BooleanValue
#endif[/code]