diff --git a/server/objects/Audiobook.js b/server/objects/Audiobook.js index e24aedd2..1cbe8cda 100644 --- a/server/objects/Audiobook.js +++ b/server/objects/Audiobook.js @@ -546,10 +546,11 @@ class Audiobook { var currOtherFileNum = this.otherFiles.length var otherFilenamesAlreadyInBook = this.otherFiles.map(ofile => ofile.filename) - var alreadyHasAbsMetadata = otherFilenamesAlreadyInBook.includes('metadata.abs') var alreadyHasDescTxt = otherFilenamesAlreadyInBook.includes('desc.txt') var alreadyHasReaderTxt = otherFilenamesAlreadyInBook.includes('reader.txt') + var existingAbMetadata = this.otherFiles.find(file => file.filename === 'metadata.abs') + // Filter out other files no longer in directory var newOtherFilePaths = newOtherFiles.map(f => f.path) this.otherFiles = this.otherFiles.filter(f => newOtherFilePaths.includes(f.path)) @@ -580,9 +581,14 @@ class Audiobook { } - // If metadata.abs is new then read it and set all defined keys (will overwrite) + // If metadata.abs is new OR modified then read it and set all defined keys (will overwrite) var metadataAbs = newOtherFiles.find(file => file.filename === 'metadata.abs') - if (metadataAbs && !alreadyHasAbsMetadata) { + var shouldUpdateAbs = !!metadataAbs && (metadataAbs.modified || !existingAbMetadata) + if (metadataAbs && metadataAbs.modified) { + Logger.debug(`[Audiobook] metadata.abs file was modified for "${this.title}"`) + } + + if (shouldUpdateAbs) { var abmetadataText = await readTextFile(metadataAbs.fullPath) if (abmetadataText) { var metadataUpdateObject = abmetadataGenerator.parse(abmetadataText) @@ -933,6 +939,12 @@ class Audiobook { var keysToCheck = ['filename', 'ext', 'mtimeMs', 'ctimeMs', 'birthtimeMs', 'size'] keysToCheck.forEach((key) => { if (existingFile[key] !== fileFound[key]) { + + // Add modified flag on file data object if exists and was changed + if (key === 'mtimeMs' && existingFile[key]) { + fileFound.modified = true + } + existingFile[key] = fileFound[key] hasUpdated = true } diff --git a/server/scanner/Scanner.js b/server/scanner/Scanner.js index 2bc31ff8..b1ebd556 100644 --- a/server/scanner/Scanner.js +++ b/server/scanner/Scanner.js @@ -85,7 +85,7 @@ class Scanner { // Sync other files first so that local images are used as cover art // TODO: Cleanup other file sync - var allOtherFiles = checkRes.newOtherFileData.concat(audiobook._otherFiles) + var allOtherFiles = checkRes.newOtherFileData.concat(checkRes.existingOtherFileData) if (await audiobook.syncOtherFiles(allOtherFiles, this.db.serverSettings.scannerPreferOpfMetadata)) { hasUpdated = true } diff --git a/server/utils/abmetadataGenerator.js b/server/utils/abmetadataGenerator.js index b8c9f677..914461b2 100644 --- a/server/utils/abmetadataGenerator.js +++ b/server/utils/abmetadataGenerator.js @@ -39,7 +39,7 @@ function generate(audiobook, outputPath) { } return fs.writeFile(outputPath, fileString).then(() => { - return filePerms(outputPath, 0o774, global.Uid, global.Gid).then(() => true) + return filePerms(outputPath, 0o774, global.Uid, global.Gid, true).then((data) => true) }).catch((error) => { Logger.error(`[absMetaFileGenerator] Failed to save abs file`, error) return false diff --git a/server/utils/filePerms.js b/server/utils/filePerms.js index 4b64851a..962a08cf 100644 --- a/server/utils/filePerms.js +++ b/server/utils/filePerms.js @@ -50,7 +50,7 @@ const chmodr = (p, mode, uid, gid, cb) => { // any error other than ENOTDIR means it's not readable, or // doesn't exist. give up. if (er && er.code !== 'ENOTDIR') return cb(er) - if (er) { + if (er) { // Is a file return fs.chmod(p, mode).then(() => { fs.chown(p, uid, gid, cb) }) @@ -77,9 +77,9 @@ const chmodr = (p, mode, uid, gid, cb) => { }) } -module.exports = (path, mode, uid, gid) => { +module.exports = (path, mode, uid, gid, silent = false) => { return new Promise((resolve) => { - Logger.debug(`[FilePerms] Setting permission "${mode}" for uid ${uid} and gid ${gid} | "${path}"`) + if (!silent) Logger.debug(`[FilePerms] Setting permission "${mode}" for uid ${uid} and gid ${gid} | "${path}"`) chmodr(path, mode, uid, gid, resolve) }) } \ No newline at end of file