thejoshwolfe / yauzl

yet another unzip library for node
MIT License
681 stars 77 forks source link

Preserving extended file attributes on Mac? #158

Closed erikjalevik closed 2 weeks ago

erikjalevik commented 1 month ago

On MacOS, some files have extended attributes (viewable with xattr -l). These don't seem to be preserved when unzipping with yauzl.

One case where this is important is when downloading an app embedded in a zip file, the Linear installer is one example. If unzipping this by double-clicking it in Finder, the extracted file has com.apple.macl, com.apple.quarantine and com.apple.provenance attributes. But if unzipping it using yauzl, these attributes are lost. Without them, MacOS refuses to launch the app, producing an error:

The application cannot be opened for an unexpected reason, 
  error=Error 
  Domain=RBSRequestErrorDomain 
  Code=5 
  "Launch failed." 
  UserInfo={
    NSLocalizedFailureReason=Launch failed., 
    NSUnderlyingError=0x6000012ac000 {
      Error 
      Domain=NSPOSIXErrorDomain 
      Code=111 
      "Unknown error: 111" 
      UserInfo={
        NSLocalizedDescription=Launchd job spawn failed
      }
    }
  }

Any thoughts on whether there's a way to preserve these when using yauzl to unzip?

thejoshwolfe commented 2 weeks ago

yauzl doesn't extract files; it enables other software to extract files. if the extended attributes you're looking for are encoded the zipfile somewhere, they should be availble to whatever software is writing to the file system, probably in the extraFields field.

Check out examples/dump.js or examples/compareCentralAndLocalHeaders.js for tools to examine a zipfile's extraFields.

Please reopen if this doesn't point you in the right direction.

erikjalevik commented 2 weeks ago

Thanks for the reply. Yes, there is indeed some data present under the extraFields property, however it's just a Buffer with 32 bytes, and I'd have no idea how to parse it into something resembling the extended attributes.

But I'm guessing this is outside the scope of yauzl.