fix: allow paths to asar archives to contain the .asar extension in directories (#20342)

This commit is contained in:
Milan Burda 2019-10-02 06:33:07 +02:00 committed by Cheng Zhao
parent 4ac4b34ae9
commit bf978e09e4
19 changed files with 204 additions and 183 deletions

View file

@ -40,8 +40,6 @@
return newArchive
}
const ASAR_EXTENSION = '.asar'
// Separate asar package's path from full path.
const splitPath = archivePathOrBuffer => {
// Shortcut for disabled asar.
@ -54,22 +52,7 @@
}
if (typeof archivePath !== 'string') return { isAsar: false }
if (archivePath.endsWith(ASAR_EXTENSION)) {
return { isAsar: true, asarPath: archivePath, filePath: '' }
}
archivePath = path.normalize(archivePath)
const index = archivePath.lastIndexOf(`${ASAR_EXTENSION}${path.sep}`)
if (index === -1) return { isAsar: false }
// E.g. for "//some/path/to/archive.asar/then/internal.file"...
return {
isAsar: true,
// "//some/path/to/archive.asar"
asarPath: archivePath.substr(0, index + ASAR_EXTENSION.length),
// "then/internal.file" (with a path separator excluded)
filePath: archivePath.substr(index + ASAR_EXTENSION.length + 1)
}
return asar.splitPath(path.normalize(archivePath))
}
// Convert asar archive's Stats object to fs's Stats object.