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

empty directories are not created #6

Closed
fredericrous opened this issue Aug 8, 2015 · 9 comments
Closed

empty directories are not created #6

fredericrous opened this issue Aug 8, 2015 · 9 comments

Comments

@fredericrous
Copy link

I download package electron-v0.30.2-darwin-x64.zip from electron repository at https://github.com/atom/electron/releases/tag/v0.28.1

I write the following and execute it with node:

var extract = require('extract-zip')
    extract("electron-v0.30.2-darwin-x64.zip", {dir: "."}, function(err) {
        console.log(err)
    })

It extract these files

➜  .electron  ls ~/.node/lib/node_modules/electron-prebuilt/dist/Electron.app/Contents/Resources 
atom.asar   atom.icns   default_app

when it should have extracted these files:

➜  .electron  ls Electron.app/Contents/Resources/
am.lproj     bn.lproj     default_app  es_419.lproj fr.lproj     hu.lproj     ko.lproj     ms.lproj     pt_PT.lproj  sr.lproj     th.lproj     zh_TW.lproj
ar.lproj     ca.lproj     el.lproj     et.lproj     gu.lproj     id.lproj     lt.lproj     nb.lproj     ro.lproj     sv.lproj     tr.lproj
atom.asar    cs.lproj     en.lproj     fa.lproj     he.lproj     it.lproj     lv.lproj     nl.lproj     ru.lproj     sw.lproj     uk.lproj
atom.icns    da.lproj     en_GB.lproj  fi.lproj     hi.lproj     ja.lproj     ml.lproj     pl.lproj     sk.lproj     ta.lproj     vi.lproj
bg.lproj     de.lproj     es.lproj     fil.lproj    hr.lproj     kn.lproj     mr.lproj     pt_BR.lproj  sl.lproj     te.lproj     zh_CN.lproj
@max-mapper
Copy link
Owner

here's the line causing the issue:

https://github.com/maxogden/extract-zip/blob/master/index.js#L28-L31

basically in extract-zip I ignore 'directory' entries, I wait until there's a file and create the directory then: https://github.com/maxogden/extract-zip/blob/master/index.js#L89

apparently all the .lproj files are empty directories which is why none of them get created. it seems like we should change the behavior of extract-zip to support empty directories, though

@smebberson
Copy link
Contributor

@maxogden, what sort of help are you looking for here?

@max-mapper
Copy link
Owner

@smebberson hi, thanks for asking. Here's what I think a PR would need:

If you have any specific code questions let me know

@smebberson
Copy link
Contributor

@maxogden, okay, doesn't seem too difficult. I just had a look and there doesn't seem to be what I'd call a test framework in place... what are you thinking a 'basic test' would look like?

@max-mapper
Copy link
Owner

@smebberson oh sorry about that. I usually use require('tape') for assertions, but skimped on the tests so far in here. For now a basic test should be a fixture zip that has empty dirs in it, and a js file that extracts it and checks to make sure the empty dir was created. I'll convert the 'tests' over to tape in the future (or feel free if you want to do it).

I also remembered another aspect of this which might be more difficult. Currently it does mkdirp for every entry's directory https://github.com/maxogden/extract-zip/blob/master/index.js#L89. I'm not sure if theres a better approach to calling mkdirp. We could call it for every empty directory, and every entry's parent directory, but that would result in calling mkdirp multiple times for the same directories.

It would work, it would just be somewhat inefficient. One thing we could do is have an in-memory cache of folders that have already had mkdirp called on them, so you know which ones you can skip. Another might be to call fs.exists on the folder first, as its cheaper than mkdirp (I think).

@smebberson
Copy link
Contributor

I think a simple in-memory cache would be best, much quicker than fs.exists multiple times for the same directory.

Reading through the code, I think it would be best to push both directories and files into the q queue, and handle either directory creation, file creation (including directory creation) and symlink all within the extractEntry function.

If you're cool with that, I'll give it a shot, and I'll write a test, and rewrite the current test using tape.

@smebberson
Copy link
Contributor

@maxogden, I've started on this with PR #9. I've started with the test harness.

@smebberson
Copy link
Contributor

@maxogden, PR #9 is now complete and empty directories are created successfully. Please review the PR with a merge and npm publish in mind?

Because the async.queue had a concurrency of one, I was able to implement what was required with out any in-memory cache being required. As directories are encountered first, I just created them first.

max-mapper added a commit that referenced this issue Sep 16, 2015
Fix for #6 (empty directories are not created)
@max-mapper
Copy link
Owner

fixed in 1.1.0

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

No branches or pull requests

3 participants