So... I did some tests about how to preserve the resource forks only with what's included with the system
- Lenguaje dominante
- PHP
- Estrellas
- 7.3k
- Forks
- 294
- Merge medio
- 14 d 16 h
- PR fusionados (30 d)
- 1
Descripción
I was experimenting with this for a while... trying out different ways to preserve resource forks with different kinds of archives... and I discovered some interesting ways to do it with what's already included with the system 🙂 I also tried out goldin and Apple's old splitforks and I'll write about those too.
Anyway 🙂
Here's some way that just seems like a new approach to doing it... I haven't heard about someone doing something like this to save/restore resource forks before...
### A convenient .tar or .cpio that just contains the parts needed to recreate the resource forks
To get a convenient .tar archive with just the files that are created for resource forks in archives (so it does not contain the "data" part of files), simply _cd_ to the directory above the one you are trying to archive and let's say the folder you are trying to archive is called "your folder"... just enter this into the Terminal then...
`tar cf - your_folder | tar cf your_folder_resource_forks.tar --include='*/._*' --include='._*' @-`
for .cpio, use this
`tar cf - your_folder | tar cf your_folder_resource_forks.cpio --format cpio --include='*/._*' --include='._*' @-`
(BTW... It doesn't even have to be a folder actually... it can be a single file too... it should work also)
If you want to also include other hidden files like .DS_Store which aren't resource forks in it, so you can keep those separate from the rest of the archive (if you maybe also want to share that archive with Windows users, but want to have an option to put those back when you recreate the resource forks), then use this
`tar cf - your_folder | tar cf your_folder_resource_forks.tar --include='*/.*' --include='.*' @-`
if you want the .cpio format, then use this
`tar cf - your_folder | tar cf your_folder_resource_forks.cpio --format cpio --include='*/.*' --include='.*' @-`
I was trying to avoid unnecessarily writing to disk... so, with these commands above, what happens is that tar would start making an archive with all files from your folder and it would start creating separate hidden files in it for the resource forks, but instead of writing that whole archive to the disk, it gets piped to tar again, for tar to create a new archive just with the files that were created for resource forks (or if you used the 2nd command I mentioned, with other hidden files too) and write it to the disk... so if the resource forks in your folder are only a small part of everything else that's in it (if it's not mostly something like those old font files that stored the fonts in resource forks) and other hidden files don't take much space too (if you choose to include them), then such a .tar (or .cpio) archive should be tiny 🙂
After that, you can compress other files in your folder without having to use .tar with some utility that does not have any support for resource forks... you can use just the regular 7z or even non-archiving formats like .gz for single files without using tar.
BTW... Keep in mind that tar would need to read all the files in a folder that you want to create those archives with resource forks for... so if you maybe have some super-huge folder on an external HDD, especially if it uses USB2, it might take a while for it to read all those files.
### A super-simple way to recreate the resource forks from that .tar
After you extract the files from 7z, you can recreate the resource forks for files that are missing them from that convenient .tar archive that just stores the resource forks 🙂
Just make sure that all files are still called the same (so the resource forks would get applied to the same files) and that the directory structure is the same...
Then go to the Terminal, make sure you are in the directory where the folder/file you uncompressed is (don't _cd_ into the folder you uncompressed... you should be in its parent directory), make sure that your_folder_resource_forks.tar is there too (next to it, not inside of the folder you uncompressed or in some other directory) and extract that .tar archive like this
`tar -xf your_folder_resource_forks.tar`
In other words, make it extract to the same folder where the files that you want it to apply those resource forks to are located... as if you want to overwrite those files, but since the data forks aren't in that .tar archive, it just adds the resource forks back to those files/folders 🙂 If their tags, custom icons or backgrounds were missing after you extracted them from 7z or some other archive formats, tags, custom icons and backgrounds should be back... if some old fonts were broken or if the aliases were broken, they should work again 🙂
If you simply extracted that .tar into another folder, tar (the one that cones with macOS) just seem to try to turn the "Apple Double" files inside of that archive back into resource forks and it would create empty data files to apply resource forks to those if the data forks aren't in the archive also and those files are missing from the folder too... Archive Utility seems to do the same for .tar
If you created a .cpio archive, you can extract using ditto and ditto would also recreate the resource fork... as with that command for tar, just make sure you _cd_ to the parent directory of the file/folder you want to apply those resource forks too first...
`ditto -c your_folder_resource_forks.cpio .`
Don't forget the dot in the end (for the current directory)
For .cpio, extracting to another folder with the Archive Utility or with just the "ditto -c your_folder_resource_forks.cpio ." does not seem to create empty files to apply resource forks to those if the files with data forks aren't there or in the archive... so the resource forks will not be recreated for missing files.
### What if you just wanted to get just those hidden ._ files in some folder?
With ditto, there's an option you can use to extract those hidden ._ files from .cpio, without ditto turning them back into resource forks... so, if you have a folder called "your_folder" and you created the "your_folder_resource_forks.cpio" for it, use this:
`ditto -x --norsrc your_folder_resource_forks.cpio your_folder_resource_forks`
The reason to create another folder for those is because there should be a file called "._your_folder" for "your_folder" and if you just extract to the current directory, you maybe have lots of other files there... and Finder does not seem to show those even if you press CMD+Shift+. to show the hidden files (you can see it if you list what's in some folder with "ls -a")... so it just seems to me more convenient to have all those hidden files inside one folder.
You could later rename "your_folder_resource_forks" to something else... that's just an example to know to which folder those files belong, so you don't mix it up.
### Another approach... using goldin
I tried splitforks (included with Apple's command line developer tools) and goldin also... they seem similar, but goldin seems better... if you don't have Xcode installed to build it, "Packages for Mac" (utilities for creating .pkg packages) includes goldin too.
Since goldin creates those hidden "._" files that are created for archives in the folder where those files are, if some folder is read-only or if you just don't want those hidden files to be added to some folder, here is what you can do...
If it's a HFS+ volume, you can use pax to create the same directory structure in some other place as a temporary folder with hard links to those files and create the hidden "._" files for resource forks there... then, after you get those "._" files, you can just delete that directory.
If your folder is called "your_folder" and you want to the directory structure and create hard links to files in it, _cd_ to that folder's parent directory, create another folder next to it called "tmp_folder" and use this
`pax -rwl your_folder tmp_folder`
On APFS you can jus duplicate some folder, since APFS does not support hard links, but duplicating a folder on APFS seems kind of similar as creating hard links, since it's not writing all those files again.
### If you want to recreate resource forks from those "._" files
If you have those "._" AppleDouble files and you want to recreate resource forks for files that have data forks only, you can use ditto for that...
If both the "._" files for resource forks and files with data forks are in a folder called "your_folder" and you want to recombine them and write them to a folder called "recombined_files", you could use this
`ditto -c --norsrc your_folder - | ditto -x - recombined_files`
I would jus recommend avoiding unnecessarily writing to the disk if you don't need to keep both versions as separate files.
You could _cd_ into that folder and create a .cpio with those "._" from those files your current directory, that you could extract with ditto when you want to add the resource forks
`find ._* */._* -print -depth | cpio -ov > resource_forks.cpio`
You could also just pipe that to ditto, for ditto to add the resource forks in one go
`find ._* */._* -print -depth | cpio -ov - | ditto -x - .`
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Evaluación
Este issue todavía no se ha evaluado.