I am trying to zip a folder up until now it has worked fine. Now I find that I am zipping a Mac .app file that has aliases in it. One of these aliases points to a folder within the same MacApp. In my recursive routine I check for the TrueItem using
tempInt2 = Source.Count
for tempInt As Integer = 1 to tempInt2
f = Source.TrueItem(tempInt)
if f = nil or not f.Exists or not f.IsReadable or f.Name = ".DS_Store" then
'ignore
elseif f.Directory then
if f.Count = 0 then 'add any empty folders
tempZipFileInfoMBS = New ZipFileInfoMBS
tempZipFileInfoMBS.SetDate(f.ModificationDate)
tempZipFileInfoMBS.ExternalFileAttributes = 0
tempZipFileInfoMBS.InternalFileAttributes = 0
tempZipFileInfoMBS.DosDate = 0 'If dos_date = 0, the plugin will calculate it from the day, month, year, hour, minute and second properties
myZipMBS.CreateFile(Path + f.Name + "/", tempZipFileInfoMBS, myExtraLocal, myExtraGlobal, myComment, myCompressionMethod, myLevel, myZip64)
else
doZipFolderWAD(myZipMBS, f, Path)
end if
else
doZipFileWAD(myZipMBS, f, Path)
end if
next
When I reach the alias to a file it correctly passes the FolderItem of the alias to my Zip method (doZipFileWAD(myZipMBS, f, Path)), but when this method receives the file and tries to open it using
tempBinaryStream = BinaryStream.Open(f, False)
it tries to read in the folder as a binary file, thus giving an error.
My question: how do I read in an alias itself as a binary stream?
I have tried things like this
Look into the ditto command line tool as that will most closely resemble the Finder’s “Compress” command. From the man page:
The command:
ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip
will create a PKZip archive similarly to the Finder's Compress function-
ality.
[quote=251224:@Kem Tekinay]Look into the ditto command line tool as that will most closely resemble the Finder’s “Compress” command. From the man page:
The command:
ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip
will create a PKZip archive similarly to the Finder's Compress function-
ality.
[/quote]
This is what App Wrapper has to use to preserve all of Apple hidden attributes and symbolic links. I’ve tried various zip utilities for Xojo, all are great for unzipping, but Apple some secret sauce that we don’t know about when it uses it’s own zip functions.
[quote=251195:@David Cox]When I reach the alias to a file it correctly passes the FolderItem of the alias to my Zip method (doZipFileWAD(myZipMBS, f, Path)), but when this method receives the file and tries to open it using
tempBinaryStream = BinaryStream.Open(f, False)
it tries to read in the folder as a binary file, thus giving an error.
My question: how do I read in an alias itself as a binary stream?
I have tried things like this
tempBinaryStream = BinaryStream.Open(f.TrueItem, False)
but can’t get it to work. Any clues?[/quote]
Okay, there’s 3 kinds of ‘Alias’ that I’m aware on OS X. Bookmarks, Symbolic Links and Links.
Bookmarks are files that contain enough data for the OS to ‘Find’ the file if it gets moved. You can read and write these with binary stream.
Symbolic Links (which is what you’re encountering in the application), is a very low level file containing just a path. These cannot be binary stream, they can be read and written with Declares, but not binary stream (except when the OS no longer sees them as Symbolic links). Symbolic links can be relative, which is why they’re used in Frameworks.
Link (or sometimes known as Hard Links) work more like Aliases, but you’d never know. They point to the same location on disk as the original file, so if the file gets moved they still work. Apps will always see these as actual files.
Surely an alias is still just a file, albeit a special kind of file. I’m still not sure why Xojo can’t binaryStream it in. I had hoped to keep my method cross-platform using ZipFileInfoMBS, but it looks like I might be out of luck with aliases. Or else I might need to compress them as a special case using ‘ditto’ then load that file into ZipFileInfoMBS.
Sorry if my explaination isn’t clear, you’re dealing with a Symbolic Link, which is not a standard file. There is only special circumstance when you can access the ‘data’ of the file with a binary stream; and that’s when the Symbolic Link is toast and no longer recognised by the OS.