How to prevent MacOS from adding dot underscore files (._whatever.html )in zip archives?

Our organisation receives zip files from Mac users which contain a ._ file in addition to the file we expect. In the past this was due to resource fork and data fork encoding limitations on other file systems. So for example, when we expect a submission that looks like this:

README.md
src/mysite.html
src/myscript.js

we generally receive a zip that contains files such as:

._README.md
README.md
src/._mysite.html
src/mysite.html
src/._myscript.js
src/myscript.js

This makes it difficult for us to process these files automatically. What instructions should we give to our Mac users to suppress these files we can’t process or handle?


Solution 1:

There's no native way to automatically exclude resource forks or other extended attribute and filesystem metadata during compression, but many 3rd party apps can do it. These files contain filesystem data that should be preserved and you get a valuable signal that you have lost data when your process strips or ignores these files.

One such is Keka (donationware, ie free direct download, paid from App Store)

enter image description here

Solution 2:

No, it is not possible to prevent the creation of resource fork files - the native zip function is designed to preserve this filesystem specific data so you would need to instruct your team to use a different tool or process.

It will likely be easier to improve your tooling to ignore files it knows are safe to ignore than to force a change in the behaviour of your users.

dot_clean on macOS

Instead, clean the files before ingesting them with macOS's dot_clean:

For each dir, dot_clean recursively merges all ._* files with their corresponding native files according to the rules specified with the given arguments. By default, if there is an attribute on the native file that is also present in the ._ file, the most recent attribute will be used.

find on Linux

On Linux, use find to recursively remove all the matching files:

find  . -type f -name '\._*' -exec rm {} \;