Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add entry.getMode() #102

Open
thejoshwolfe opened this issue Dec 18, 2018 · 4 comments
Open

add entry.getMode() #102

thejoshwolfe opened this issue Dec 18, 2018 · 4 comments

Comments

@thejoshwolfe
Copy link
Owner

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.

@melroy89
Copy link

Never implemented?

@clarkttfu
Copy link

+1

@thejoshwolfe
Copy link
Owner Author

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.

@ayushmanchhabra
Copy link

ayushmanchhabra commented Mar 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants