Folderitem oddities

I’m getting some strange behavior for restoring folderitems from the preferences. When the folderitem is there then all is well, but when I move the folderitem to the trash and then try to get the folderitem I get one of 2 behaviors:

  1. Folderitem with correct absolute path, exists = false, native path = “”
    or
  2. Folderitem with lots of numbers in name and native path (not reproducable).

Here is the code that I use to get the folderitem. It hasn’t changed in years.

[code]Public Function getPrefFolderitem(fieldName as string) as Folderitem

dim theCFPrefs as new CFPreferencesMBS
Dim theCFObject As CFObjectMBS = theCFPrefs.CopyAppValue(NewCFStringMBS(fieldName), theCFPrefs.kCFPreferencesCurrentApplication)
if theCFObject = Nil then Return nil

dim theFolderitem as FolderItem
if theCFObject.TypeDescription = “CFString” then
dim FieldValue as String = CFStringMBS(theCFObject).str
theFolderitem = Volume(0)
dim theSaveInfo as String = DecodeBase64MBS(FieldValue)
return theFolderitem.getRelative(theSaveInfo)
end if

End Function[/code]

Shouldn’t the saveinfo show me that I moved the file to the trash? Why is the absolute path correct and the native path empty?

When I move a complete folder into the trash I get the correct folderitem pointing to the trash. When I move the file into the trash with 2016r4 I get at the correct native path.

When I do a simple test with

dim d as folderitem = specialfolder.desktop d = d.child("blabla")

then I get the correct native path.

Xojo 2017r1, MacOS 10.11.6.

That’s a bit inefficient. Better:

if theCFObject isA CFStringMBS then

How do you move the folder? In Finder, or in your own code? If you move a FolderItem in code, you may need to reconstruct the FolderItem. Either way, it sounds like a cashing issue.

I moved the file in Finder. How do I un-cache the folderitem? How can a folderitem be cached???

You’re not providing all the information and parameters, leaving us to guess.

Scratching head. What information is missing?

I save a folderitem to the prefs:

[code]Public Sub setPrefFolderitem(fieldName as string, fieldValue as Folderitem)

dim theCFObject As CFObjectMBS

if fieldValue = nil then
theCFObject = NewCFStringMBS("")
else
theCFObject = NewCFStringMBS(EncodeBase64(fieldValue.GetSaveInfo(volume(0))))
end if

dim theCFPrefs as new CFPreferencesMBS
theCFPrefs.SetAppValue(NewCFStringMBS(FieldName), theCFObject, theCFPrefs.kCFPreferencesCurrentApplication)
if not theCFPrefs.AppSynchronize(theCFPrefs.kCFPreferencesCurrentApplication) Then Break

End Sub[/code]

Let’s say it’s a file on the desktop with a shell path of /Users/beatrixwillius/Desktop/Mail\ Archive.vdb . I quit the app. In the Finder I move the file to the trash. I open my app again and restore the folderitem with the code from above. Instead of getting the original folderitem I get a half-baked folderitem with an empty native path when using Xojo 2017r1.

How are you restoring it?

The documentation says that GetRelative is able to restore moved items that are saved when you pass nil for relative path. I bet making the relative to item Volume(0) is making your app able to track the moved item since that’s not a relative path.

Files on Mac are tracked using the underlying unix nodes, not direct paths. So if the OS is able to figure out which node you wanted, it will be able to find it in the Trash. The Trash is not just another folder, it’s a magical place on Mac where you need to use NSWorkspace to get files in and out, so that might be why you don’t get a NativePath.

First time I have ever seen “trash can” and “magical place” used in the same sentence :smiley:

@David S: me to.

I’m using

ArchiveFolderitem = Globals.thePrefs.getPrefFolderitem("Export_ValentinaArchivePath")

The code is ages old. That it’s not very good at handling items in the trash I’ve noticed, too. Nevertheless, it has worked in the last years and before 2017r1 I have never seen such a mangled folderitem. Unfortunately, I didn’t make a screenshot of the other result I had with a folderitem native path with lots of numbers (20 - 30???).

As soon as my main development machine is back to working I’ll do some more testing.