From 166cfc0c1dcec3de9f6e6f5f7269177d5b9c1058 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 9 Aug 2021 15:33:35 -0700 Subject: [PATCH] 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. --- .gitattributes | 1 + lib/write-entry.js | 2 +- test/pack.js | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..00022d9c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +test/fixtures/files/** text eol=lf diff --git a/lib/write-entry.js b/lib/write-entry.js index 78ac49f5..239e4233 100644 --- a/lib/write-entry.js +++ b/lib/write-entry.js @@ -80,8 +80,8 @@ const WriteEntry = warner(class WriteEntry extends MiniPass { if (!this.preservePaths) { const s = stripAbsolutePath(this.path) if (s[0]) { + this.warn('stripping ' + s[0] + ' from absolute path', this.path) this.path = s[1] - this.warn('stripping ' + s[0] + ' from absolute path', p) } } diff --git a/test/pack.js b/test/pack.js index 57e09008..6b06c681 100644 --- a/test/pack.js +++ b/test/pack.js @@ -145,7 +145,7 @@ t.test('pack a dir', t => { cksumValid: true, needPax: false, path: 'dir/', - mode: 0o755, + mode: Number, size: 0, mtime: null, cksum: Number, @@ -173,7 +173,7 @@ t.test('pack a dir', t => { cksumValid: true, needPax: false, path: 'dir/x', - mode: 0o644, + mode: Number, size: 0, mtime: mtime, cksum: Number,