@@ -23,6 +23,7 @@ const CLOSE = Symbol('close')
2323const MODE = Symbol ( 'mode' )
2424const warner = require ( './warn-mixin.js' )
2525const winchars = require ( './winchars.js' )
26+ const stripAbsolutePath = require ( './strip-absolute-path.js' )
2627
2728const modeFix = require ( './mode-fix.js' )
2829
@@ -52,12 +53,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
5253 this . on ( 'warn' , opt . onwarn )
5354
5455 let pathWarn = false
55- if ( ! this . preservePaths && path . win32 . isAbsolute ( p ) ) {
56- // absolutes on posix are also absolutes on win32
57- // so we only need to test this one to get both
58- const parsed = path . win32 . parse ( p )
59- this . path = p . substr ( parsed . root . length )
60- pathWarn = parsed . root
56+ if ( ! this . preservePaths ) {
57+ const [ root , stripped ] = stripAbsolutePath ( this . path )
58+ if ( root ) {
59+ this . path = stripped
60+ pathWarn = root
61+ }
6162 }
6263
6364 this . win32 = ! ! opt . win32 || process . platform === 'win32'
@@ -351,10 +352,12 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
351352 this . on ( 'warn' , opt . onwarn )
352353
353354 let pathWarn = false
354- if ( path . isAbsolute ( this . path ) && ! this . preservePaths ) {
355- const parsed = path . parse ( this . path )
356- pathWarn = parsed . root
357- this . path = this . path . substr ( parsed . root . length )
355+ if ( ! this . preservePaths ) {
356+ const [ root , stripped ] = stripAbsolutePath ( this . path )
357+ if ( root ) {
358+ this . path = stripped
359+ pathWarn = root
360+ }
358361 }
359362
360363 this . remain = readEntry . size
0 commit comments