News for hackers. Stuff that matters.
Re:Explainer: .DS_Store Files by jeroenhd on Saturday November 27, 2021 @06:48PM (#29364774)
".DS_Store", or, "how to tell if a ZIP file was created by a macOS user".
Re:Explainer: .DS_Store Files by RKearney on Sunday November 28, 2021 @12:49AM (#29366525)
"Desktop.ini" and "thumbs.db", or, "how to tell if a ZIP file was created by a Windows user".
Re:Explainer: .DS_Store Files by sebazzz on Sunday November 28, 2021 @06:43AM (#29368109)
Yes, but these files only get made, when:

- There is anything to create a thumbnail cache for

- User has applied custom settings like a folder icon or designation to the folder

Re:Explainer: .DS_Store Files by Lhiw on Sunday November 28, 2021 @02:51AM (#29367029)
".tar.gz" or how to tell the file was archived by a Linux user.
Re:Explainer: .DS_Store Files by folmar on Sunday November 28, 2021 @11:10AM (#29369979)
.tar.Z or how to tell the file was archived by a Real Man[tm].
Re:Explainer: .DS_Store Files by marcodiego on Saturday November 27, 2021 @08:34PM (#29365390)
I received some ZIP files from macOS users which contain a directory called __MACOSX .
Re:Explainer: .DS_Store Files by zerocrates on Saturday November 27, 2021 @09:12PM (#29365565)
I seem to recall that the __MACOSX folder is there to support resource forks? Something along those lines at any rate.
Re:Explainer: .DS_Store Files by bombcar on Saturday November 27, 2021 @09:43PM (#29365723)
Yep. And since many files don’t have resource forks it’s kinda rare. But any directory you look at basically gets a .DS_STORE.

I remember hiding those from windows clients with samba, and hiding thumbs.db from mac clients over netatalk (and samba)

Re:Explainer: .DS_Store Files by dunham on Sunday November 28, 2021 @12:38AM (#29366474)
It looks like they store the extended attributes in the __MACOSX tree too. And everything you download from the web has extended attributes describing the original URL and page that linked to it. (With chrome/safari, I haven't checked firefox.)

It looks like the finder "compress" functionality will include __MACOSX, and the command line zip doesn't.

If you run `xattr -l` on something in your Downloads, you should see the kMDItemWhereFroms metadata. mdls shows it too, but also includes other data that is extracted from the file itself.

You can also search on that metadata:

    mdfind kMDItemWhereFroms:citeseerx
Re:Explainer: .DS_Store Files by nicbou on Sunday November 28, 2021 @07:30AM (#29368402)
Another issue with zip files on OSX:

> Zip files can encode their file names in two ways: CP437, or unicode.

> Each operating system does it wrong, but in a different way. For instance, Mac OS encodes its zip files as unicode, but doesn't set bit 11 correctly, so Python (correctly) reads them as CP437, and garbles the non-ASCII characters in file names.

> I wrote a quick and dirty workaround for Mac OS archives: if the file doesn't exist, encode the name as CP437 and check again. I'll think of something more clever if I ever switch to another OS.

https://nicolasbouliane.com/projects/timeline

Re:Explainer: .DS_Store Files by jeroenhd on Sunday November 28, 2021 @08:50AM (#29368880)
Woah, that explains a lot of weird bugs, actually! This is very useful information, thanks!
Re:Explainer: .DS_Store Files by makecheck on Saturday November 27, 2021 @08:38PM (#29365407)
Yep, I write scripts to clean up zip files because the default behavior is so bad for cross-platform.
Re:Explainer: .DS_Store Files by smarx007 on Saturday November 27, 2021 @08:45PM (#29365432)
Could you please share it?
Re:Explainer: .DS_Store Files by makecheck on Saturday November 27, 2021 @09:20PM (#29365601)
This is my script to “clean up” a typical macOS zip file. It assumes you’ve started by asking the Finder to “Compress” (which creates a zip file but one riddled with macOS-isms).

    #!/bin/bash
    
    zipfile=$1
    if [ "x$zipfile" = "x" ] ; then
      echo "$0: .zip file expected" >&2
      exit 1
    fi
    
    zip -d "${zipfile}" "__MACOSX*"
    zip -d "${zipfile}" ".DS_Store"
    zip -d "${zipfile}" "*/.DS_Store"
    unzip -l "${zipfile}" | sort -k 5
Re:Explainer: .DS_Store Files by rahen on Sunday November 28, 2021 @05:41AM (#29367853)
You probably want to test:

    if [ ! -f "$zipfile" ]
Instead of

    if [ "x$zipfile" = "x" ]
Re:Explainer: .DS_Store Files by smarx007 on Sunday November 28, 2021 @05:41PM (#29373892)
Thank you! I took your script, suggestions in this thread and added some of my sauce:

    #!/usr/bin/env bash

    set -exuo pipefail
        
    VERBOSE=false
    while getopts "v" arg; do
    case $arg in
        v) VERBOSE=true;;
    esac
    done
    shift $((OPTIND-1))


    zipfile=$1
    if [ ! -f "$zipfile" ] || [ ! "${zipfile##*.}" = "zip" ] ; then
        echo "$0: .zip file expected" >&2
        exit 1
    fi

    zip -d "${zipfile}" "__MACOSX*" ".DS_Store" "*/.DS_Store" "Thumbs.db" "*/Thumbs.db"

    if [ $VERBOSE = true ]; then
        unzip -l "${zipfile}" | sort -k 5
    fi
Re:Explainer: .DS_Store Files by xorcist on Sunday November 28, 2021 @08:17AM (#29368672)
Processing the zip file three times over seems a bit excessive?

  zip -d "${zipfile}" "__MACOSX*" ".DS_Store" "*/.DS_Store"
Re:Explainer: .DS_Store Files by makecheck on Sunday November 28, 2021 @10:03AM (#29369393)
True but performance wasn’t the goal (I tend to run it once on smallish files).

This is easier to extend if I see something new to exclude (or comment-out some rule).

Re:Explainer: .DS_Store Files by bombcar on Saturday November 27, 2021 @09:43PM (#29365731)
BetterZip has an option for “clean” zips you can enable as the default for create.
Re:Explainer: .DS_Store Files by thought_alarm on Sunday November 28, 2021 @05:48AM (#29367892)
Why does Windows not deal with hidden files correctly?

It's 2021. Hidden dot-files are not a new thing.

Re:Explainer: .DS_Store Files by jeroenhd on Sunday November 28, 2021 @08:49AM (#29368879)
Hidden dot files were introduced as a bug and left to linger because they were kind of useful. It all started when someone tried to hide . and .. from the output of ls and messed up the if statement to only check if the first letter in the filename was a period instead of testing for the intended use cases. People then copied that behaviour around because it was a cool new trick, not because it was set up as a standard.

The Windows method, leveraging file attributes, is actually much cleaner in my opinion. You can set the hidden attribute in ZIP files and most tools do for OS specific files and folders, but I don't want my ZIP tool to put files on my file system that I don't get to see first so I always turn them on.

Windows does the same thing with desktop.ini, but I rarely encounter those anymore. It used to be that every ZIP had a bunch of thumbs.db files but Microsoft seems to have cut that out.

Re:Explainer: .DS_Store Files by exikyut on Sunday November 28, 2021 @09:16AM (#29369046)
Alternatively, https://www.google.com/search?q=intitle%3A%22index+of+%2F%22...: "how to tell if an open directory index was created by a macOS user"
Re:Explainer: .DS_Store Files by arendtio on Sunday November 28, 2021 @07:28AM (#29368388)
Not just zip files, USB drives too.
Re:Explainer: .DS_Store Files by freitasm on Saturday November 27, 2021 @07:03PM (#29364864)
Came here to say this. Leaving satisfied.
Re:Explainer: .DS_Store Files by zibzab on Saturday November 27, 2021 @07:21PM (#29364983)
Also, how to tell the new Sr dev mgmt just hired is really a jr dev.

Yes, I am talking about .gitignore

Re:Explainer: .DS_Store Files by jcoder on Sunday November 28, 2021 @12:27AM (#29366426)
I can’t tell if you mean they included `.DS_Store` in their ignore file or left it out, but including it is just good practice.