-
Notifications
You must be signed in to change notification settings - Fork 17
Fix native zip #13
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
Fix native zip #13
Conversation
|
Thanks @remithomas I haven't had a chance to test on various platforms (Win, OSX, Linux). Would be happy to merge once someone validates that. |
|
We should really set up https://docs.travis-ci.com/user/multi-os/ and https://www.appveyor.com/ |
nfriedly
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again! This is obviously an important fix, but it's causing a couple of test failures that need to be addressed. More comments below.
| var args = ["--quiet", "--recurse-paths", dest].concat(source); | ||
| cp.spawn("zip", args, done); | ||
| var zip = cp.spawn("zip", args); | ||
| zip.on("exit", done); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This passes in the exit code as the first argument, but the first argument returned to the user should be an error or null.
Come to think of it.. we should add a zip.on('error', ...); to capture any errors.
Also, lets use the close event rather than exit - because it guarantees that all underlying resources have been closed. https://nodejs.org/dist/latest-v10.x/docs/api/child_process.html#child_process_class_childprocess
So, this is my variation:
function nativeZip(dest, source, done) {
var args = ["--quiet", "--recurse-paths", dest].concat(source);
var zip = cp.spawn("zip", args);
var error = null;
zip.on("error", function(err) {
error = err;
});
zip.on("close", function(code) {
if (code !== 0 && !error) {
error = new Error(
"Unexpected exit code from native zip command: " + code
);
}
if (error) {
done(error);
} else {
done();
}
});
}That allows some of the tests to pass, but there is still one failure:
1) bestzip
When archiving a dummy file
Valid archive
should contain valid data after unarchive:
Uncaught AssertionError: expected [Error: ENOENT: no such file or directory, open '/Users/nathan.friedly/projects/node-bestzip/test/validArchiveExtract/file1.js'] to not exist
at ReadFileContext.callback (test/bestzip.js:108:35)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13)
The wording of that message is a little confusing, but basically the test expected the file to be extracted to ./file1.js but it actually gets extracted to ./Users/nathan.friedly/projects/node-bestzip/test/fixtures/file1.js
Basically, the archive that macOS's native zip creates when passed an absolute path includes that entire file path! So, we need to do something to normalize that so that both node and native produce archives that contain the same file structure from a given input. Perhaps strip the CWD from the beginning of the input strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, on second thought, I think nodeZip should emulate the native behavior. So, the test is wrong, and the nodeZip implimentation is wrong.. and it'll be a major version bump :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You right! we should emulate it !
Yes this is major bump.
We should add this in todo list and close this one ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking just extend this one - make the test expect the native behavior, and then update the node zip to pass the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have time available to work on that?
| nodeZip(dest, sources, done); | ||
|
|
||
| if (which === NATIVE) { | ||
| nativeZip(dest, sources, done); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay!
spawnmethod for nativezip