mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Cleanup empty directiories inside the temp extraction dir
This commit is contained in:
parent
0d08aecd56
commit
072028c740
@ -71,6 +71,17 @@ class CbrComicBookExtractor extends AbstractComicBookExtractor {
|
|||||||
return filePaths
|
return filePaths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeEmptyParentDirs(file) {
|
||||||
|
let dir = Path.dirname(file)
|
||||||
|
while (dir !== '.') {
|
||||||
|
const fullDirPath = Path.join(this.tmpDir, dir)
|
||||||
|
const files = await fs.readdir(fullDirPath)
|
||||||
|
if (files.length > 0) break
|
||||||
|
await fs.remove(fullDirPath)
|
||||||
|
dir = Path.dirname(dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async extractToBuffer(file) {
|
async extractToBuffer(file) {
|
||||||
if (!this.archive) return null
|
if (!this.archive) return null
|
||||||
const extracted = this.archive.extract({ files: [file] })
|
const extracted = this.archive.extract({ files: [file] })
|
||||||
@ -78,6 +89,7 @@ class CbrComicBookExtractor extends AbstractComicBookExtractor {
|
|||||||
const filePath = Path.join(this.tmpDir, files[0].fileHeader.name)
|
const filePath = Path.join(this.tmpDir, files[0].fileHeader.name)
|
||||||
const fileData = await fs.readFile(filePath)
|
const fileData = await fs.readFile(filePath)
|
||||||
await fs.remove(filePath)
|
await fs.remove(filePath)
|
||||||
|
await this.removeEmptyParentDirs(files[0].fileHeader.name)
|
||||||
Logger.debug(`[CbrComicBookExtractor] Extracted file "${file}" from comic book "${this.comicPath}" to buffer, size: ${fileData.length}`)
|
Logger.debug(`[CbrComicBookExtractor] Extracted file "${file}" from comic book "${this.comicPath}" to buffer, size: ${fileData.length}`)
|
||||||
return fileData
|
return fileData
|
||||||
}
|
}
|
||||||
@ -86,9 +98,9 @@ class CbrComicBookExtractor extends AbstractComicBookExtractor {
|
|||||||
if (!this.archive) return false
|
if (!this.archive) return false
|
||||||
const extracted = this.archive.extract({ files: [file] })
|
const extracted = this.archive.extract({ files: [file] })
|
||||||
const files = [...extracted.files]
|
const files = [...extracted.files]
|
||||||
const fileEntry = files[0]
|
const extractedFilePath = Path.join(this.tmpDir, files[0].fileHeader.name)
|
||||||
const extractedFilePath = Path.join(this.tmpDir, fileEntry.fileHeader.name)
|
|
||||||
await fs.move(extractedFilePath, outputFilePath, { overwrite: true })
|
await fs.move(extractedFilePath, outputFilePath, { overwrite: true })
|
||||||
|
await this.removeEmptyParentDirs(files[0].fileHeader.name)
|
||||||
Logger.debug(`[CbrComicBookExtractor] Extracted file "${file}" from comic book "${this.comicPath}" to "${outputFilePath}"`)
|
Logger.debug(`[CbrComicBookExtractor] Extracted file "${file}" from comic book "${this.comicPath}" to "${outputFilePath}"`)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user