Trying to read the contents of an alias always gives me the actual file contents

Xojo 2020 r1.2 / macOS Big Sur 11.1.

Trying to read the contents of an alias file (not the linked file), and binarystream / textinputstream return the contents of the linked file, not the alias.

Even doing “cat” on the terminal to display the contents of the alias via the terminal returns the contents of the linked file, not the link. Some for other apps.

I have verified that I am trying to read the alias as the folderitem.length is 30 bytes, instead of 2.7 MB.

Am I really just too tired and missing something, or has this changed recently?

did you use TrueChild or TrueItem to get the folderitem ?

Can’t get the alias data either:

dim f as folderitem = getopenfolderitem("")
dim b as BinaryStream = BinaryStream.Open(f)
dim s as String = b.Read(b.Length)

Got 2 files on the desktop: a png and the alias to the png. s contained the data of the png.

Xojo 2020r2.1, BS, M1.

This gets you a FolderItem that points to the alias rather than resolving to the file that the alias points to:

Var picAliasFile As FolderItem = SpecialFolder.Desktop.Child("PicAlias", False)

Thanks Paul,
Getting a folderitem that references the alias is not a problem, it is reading the contents that is the problem.

I confirmed that I had the alias by checking the length which showed 30 bytes instead of 2.7 mb.

Sigh… That is what I am seeing also :frowning: I think that this may be a OS level change, because CAT also shows the referenced file and not the alias data.

In my quick test (2020r2.1, Big Sur 11.1, x86), I seem to be able to get the data from the alias itself. Here’s what I see in the debugger:

Hmmm… In that simple test it does also work here… So what is going on in my app.

Edit 2: Take that back! For some reason I was using the folderitem.length as a gauge of how much data to read. Once I updated it to use the stream length…

Edit 3: This updated code also shows paths to confirm.

Try this code.

dim rootPath as string            = app.executableFile.parent.parent.nativePath
dim rpl as integer                = len( rootPath )

dim executableAlias as folderItem = app.executableFile.parent.parent.child( "Frameworks" ).child( "XojoFramework.framework" ).trueChild( "XojoFramework" )
dim executableFile as folderItem  = executableAlias.parent.child( )

dim fileStreamPath as string      = executableFile.nativePath
fileStreamPath                    = right( fileStreamPath, len( fileStreamPath ) - rpl )
dim fileStream as binaryStream    = executableFile, false )
dim fileStreamLength as Uint64    = fileStream.length
dim fileContents as string        = fileStream.length )

dim aliasStreamPath as string     = executableAlias.nativePath
aliasStreamPath                   = right( aliasStreamPath, len( aliasStreamPath ) - rpl )
dim aliasStream as binarystream   = executableAlias, false )
dim aliasStreamLength as Uint64   = aliasStream.length
dim aliasContents as string       = aliasStream.length )


I’ve tried again with my 3 liner - making sure that I really get the alias. And I still see the same issue:


Bildschirmfoto 2021-01-22 um 15.19.41


This ain’t no alias!

1 Like

I get the same incorrect result with Xojo 2020r2.1 on 11.1 (x86).

I just moved the project over to macOS 10.14.6 with Xojo 2019r3.1 and I get the same results…

Get te Folderitem to the alias, set it in the constructor of a new folderitem as paul showed.

Ope that file (actual alias) in the stream

A test using your code:

  • I created an alias next to the XojoFramework (from the XojoFramework Alias) and renamed it Test:
  • using your code I get the same problem (when .trueChild( “XojoFramework” ) )
  • changed that to “Test” and it works:

Last test:

  • Instead of using the finder to create the Alias, I used terminal and ln -s XojoFramework Test
  • it is only a 13 bytes file
  • when I run the same code, now I get:

I guess an Alias is not the same as a link.

Awake now and certainly more lucid. So yes, according to Xojo and to the Finder, Aliases and Symbolic Links are both Aliases, but under the hood they’re not.

Reading the UTI from the Alias tells me the difference, then I can use other API to read the contents of the Symbolic Link. Just not a Xojo “stream”. I get the feeling that this is not Xojo’s fault, it’s just how the OS “works”.

Written up my experiences with trying to use Xojo to handle Aliases. Including a bug in the folderitem class <>

On MacOS ? is this something new (BS ? Catalina ?) First time I heard about that in macOS.

Go to terminal and type “man ln”, is not new.

Yes on macOS. It’s just that Finder and Xojo lump them and bookmarks together as Aliases, so you may have already encountered them, just never knew. They only cause problems for me, because I was trying to get at the data of the alias and it was failing, because it is a Symbolic Link and I needed to use an alternative method for it.