SaveInfo broken?

I have been using SaveInfo as a kind of pseudo-alias, and it’s worked in the past, but recently appears to be broken, at least on my Mac.

zSaveInfo = f.GetSaveInfo( nil )
// Now move the file and ..
f = GetFolderItem( zSaveInfo ) // NIL!!

Before I go through the test project/Feedback thing, can anyone confirm, or tell me what I’m doing wrong?

(For my immediate project, I started using MacFSRef on the Mac, which works as expected.)

Our CFBookmarkMBS module may help as replacement.

I’m using this in a generic, public class though. But that’s good to know anyway.

Which version of macOS and which version of Xojo? Some things that are broken work better in you know what.

Unfortunately, this is noted as removed in Xojo 2019r2 :frowning:

Read here: Deprecations .

@Kem Tekinay — FSRef are deprecated and SaveInfo seems to use deprecated Carbon calls. Use BookmarkData available to CFURL and NSURL objects instead.

I’ve filed a bug report.

WORKAROUND with declares

If you are in a hurry, copy and paste the two following methods into a module. It is a draft but it works, even on APFS volumes.

[code]Public Function GetBookmarkData(extends f as FolderItem, relativeTo as FolderItem = nil, Mode as Integer = 0) as String
//# Mimicks (better) FolderItem.GetSaveInfo with modern system calls. Mode is actually not used. The bookmark will be relative if and only if you set a RelativeTo FolderItem.

declare function NSClassFromString Lib CocoaLib ( aClassName as CFStringRef ) As Ptr
declare function URLWithString lib CocoaLib selector “URLWithString:” ( cls as Ptr, URLString as CFStringRef ) as Ptr
declare function BookmarkDataWithOptions lib CocoaLib selector “bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:” (id as Ptr, options as Integer, rsrc as Ptr, relativeTo as Ptr, byref error as Ptr) as Ptr
declare function DataLength lib CocoaLib selector “length” (id as Ptr) as integer
declare sub DataBytes lib CocoaLib selector “getBytes:length:” (id as Ptr, dest as Ptr, length as integer)

const CocoaLib = “Cocoa.framework”

dim url as Ptr = URLWithString( NSClassFromString( “NSURL” ), f.URLPath )
dim relativeNSURL as Ptr
dim err as Ptr

if relativeTo<>nil then
relativeNSURL = URLWithString( NSClassFromString( “NSURL” ), relativeTo.URLPath )
end if

dim data as Ptr = BookmarkDataWithOptions( url, 0, nil, relativeNSURL, err )

if data<>nil then
dim L as integer = DataLength( data )
dim mb as new MemoryBlock( L )
DataBytes data, mb, L
return mb.StringValue( 0, L )
end if

End Function
[/code]

[code]Public Function ResolveBookmark(data as String, relativeTo as FolderItem = nil) as FolderItem
//# Resolves a bookmark and returns the corresponding FolderItem. If you created a relative Bookmark, you MUST provide the same RelativeTo parameter as during creation.

declare function NSClassFromString Lib CocoaLib ( aClassName as CFStringRef ) As Ptr
declare function URLWithString lib CocoaLib selector “URLWithString:” ( cls as Ptr, URLString as CFStringRef ) as Ptr
declare function URLByResolvingBookmarkData lib CocoaLib selector “URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:” (cls as Ptr, data as Ptr, options as integer, relativeto as Ptr, byref stale as Boolean, byref err as Ptr) as Ptr
declare function DataWithBytes lib CocoaLib selector “dataWithBytes:length:” (cls as Ptr, bytes as Ptr, length as integer) as Ptr
declare function absoluteString lib CocoaLib selector “absoluteString” (id as Ptr) as CFStringRef

const CocoaLib = “Cocoa.framework”

dim url as Ptr
dim relativeNSURL as Ptr
dim stale as boolean
dim err as Ptr

if relativeTo<>nil then
relativeNSURL = URLWithString( NSClassFromString( “NSURL” ), relativeTo.URLPath )
end if

dim mb as MemoryBlock = data
dim nsdata as Ptr = DataWithBytes( NSClassFromString( “NSData” ), mb, mb.size )

url = URLByResolvingBookmarkData( NSClassFromString( “NSURL” ), nsdata, 0, relativeNSURL, stale, err )

if url<>nil then
return new FolderItem( absoluteString( url ), FolderItem.PathTypeURL )
end if

End Function
[/code]

Against what ?

A Deprecated and Removed feature ?

Against SaveInfo. It’s not removed, in fact they fixed another beta bug with it recently.

@Emile Schwarz — The feature still exists but Xojo never cared to move to up-to-date methods

That link doesn’t show me that, but it makes no difference if SaveInfo is deprecated or not, It’s still a part of the language and should work as documented. I told you that Xojo has already fixed bugs in SaveInfo for 2019R2, so obviously they care about this.

<https://xojo.com/issue/57122>

Let Xojo sort this out and reply to the bug report.

Works like a charm, @StphaneMons .

“This case has been fixed and is waiting verification from our testing staff.”