yauzl icon indicating copy to clipboard operation
yauzl copied to clipboard

add entry.getMode()

Open thejoshwolfe opened this issue 6 years ago • 4 comments

This issue was raised in #101.

We should implement a function to read externalFileAttributes and return the mode aka permission bits. it might be as simple as:

Entry.prototype.getMode = function() {
  return entry.externalFileAttributes >>> 16;
}

but this may only be correct when the entry is made by a unix zipfile creator. We should investigate how various zipfile creators encode permissions, especially windows clients.

thejoshwolfe avatar Dec 18 '18 13:12 thejoshwolfe

Never implemented?

melroy89 avatar Feb 22 '23 16:02 melroy89

+1

clarkttfu avatar Aug 19 '23 12:08 clarkttfu

Here's what we need to test before we can implement this:

On Windows, create zip archives with each of the following tools:

  1. Compressed folder (builtin to Explorer)
  2. a .NET program using System.IO.Compression.ZipFile
  3. 7-Zip? Other "popular" zipping programs? I'm trying to enumerate the archive creators that have been problematic in the past, but i've been doing this for a long time, so perhaps these tools are obsolete at this point in modern history.

The archive should contain:

  • a .txt file
  • an .exe file
  • a file whose permission bits have been modified in WSL with chmod +x
  • symlinks created in WSL to each of the above three files using ln -s. (I don't think target permissions will matter, but let's test.)
  • Windows shortcuts to the .exe and .txt files
  • Windows native symlinks to the .exe and .txt files created using mlink or something. I don't know much about this. see here: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
  • bonus round: in addition to WSL, also perform the above WSL steps using cygwin. and/or also using Linux on a removable media formatted in NTFS, and then transfer the media to a Windows machine to build the archives.

With all that data, I would be confident enough to implement and document a .getMode() function. I can support Linux just fine, but Windows is inaccessible to me at this time in my life, and I don't want to exclude Windows support.

I'm less enthusiastic about supporting Mac due to the atrocious Archive Utility implementation. If it's buggy, let it be buggy.

thejoshwolfe avatar Mar 07 '24 12:03 thejoshwolfe

To unzip MacOS and Linux archives, I use this logic:

function modeFromEntry(entry) {
  const attr = entry.externalFileAttributes >> 16 || 33188;

  return [448, 56, 7
    .map(mask => attr & mask)
    .reduce((a, b) => a + b, attr & 61440);
}

const isSymlink = const isSymlink = ((modeFromEntry(entry) & 0o170000) === 0o120000);

Been a while since I've looked at this code so can't remember the exact implementation details. Will try to dig up the references I used to put this together.

ayushmanchhabra avatar Mar 30 '24 07:03 ayushmanchhabra