Skip to content

Commit 166cfc0

Browse files
committed
fix: refactoring to pass tests on Windows
This is a larger refactoring than I tend to prefer to do in a single commit, but here goes. - The path normalization of \ to / is made more comprehensive. - Checking to ensure we aren't overwriting the cwd is done earlier in the unpack process, and more thoroughly, so there is less need for repetitive checks later. - The cwd is checked at the start in our recursive mkdir, saving an extra fs.mkdir call which would almost always result in an EEXIST. - Many edge cases resulting in dangling file descriptors were found and addressed. (Much as I complain about Windows stubbornly refusing to delete files currently open, it did come in handy here.) - The Unpack[MAKEFS] methods are refactored for readability, and no longer rely on fall-through behavior which made the sync and async versions slightly different in some edge cases. - Many of the tests were refactored to use async rimraf (the better to avoid Windows problems) and more modern tap affordances. Note: coverage on Windows is not 100%, due to skipping many tests that use symbolic links. Given the value of having those code paths covered, I believe that adding istanbul hints to skip coverage of those portions of the code would be a bad idea. And given the complexity and hazards involved in mocking that much of the filesystem implementation, it's probably best to just let Windows not have 100% coverage.
1 parent ce5148e commit 166cfc0

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/fixtures/files/** text eol=lf

lib/write-entry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
8080
if (!this.preservePaths) {
8181
const s = stripAbsolutePath(this.path)
8282
if (s[0]) {
83+
this.warn('stripping ' + s[0] + ' from absolute path', this.path)
8384
this.path = s[1]
84-
this.warn('stripping ' + s[0] + ' from absolute path', p)
8585
}
8686
}
8787

test/pack.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ t.test('pack a dir', t => {
145145
cksumValid: true,
146146
needPax: false,
147147
path: 'dir/',
148-
mode: 0o755,
148+
mode: Number,
149149
size: 0,
150150
mtime: null,
151151
cksum: Number,
@@ -173,7 +173,7 @@ t.test('pack a dir', t => {
173173
cksumValid: true,
174174
needPax: false,
175175
path: 'dir/x',
176-
mode: 0o644,
176+
mode: Number,
177177
size: 0,
178178
mtime: mtime,
179179
cksum: Number,

0 commit comments

Comments
 (0)