Fix:Watcher waits for files to finish transferring before scanning #1362 #2248

This commit is contained in:
advplyr 2023-10-25 16:53:53 -05:00
parent ef1cdf6ad2
commit 8dc4490169
2 changed files with 97 additions and 30 deletions

View file

@ -38,22 +38,14 @@ function isSameOrSubPath(parentPath, childPath) {
}
module.exports.isSameOrSubPath = isSameOrSubPath
async function getFileStat(path) {
function getFileStat(path) {
try {
var stat = await fs.stat(path)
return {
size: stat.size,
atime: stat.atime,
mtime: stat.mtime,
ctime: stat.ctime,
birthtime: stat.birthtime
}
return fs.stat(path)
} catch (err) {
Logger.error('[fileUtils] Failed to stat', err)
return false
return null
}
}
module.exports.getFileStat = getFileStat
async function getFileTimestampsWithIno(path) {
try {
@ -72,12 +64,25 @@ async function getFileTimestampsWithIno(path) {
}
module.exports.getFileTimestampsWithIno = getFileTimestampsWithIno
async function getFileSize(path) {
var stat = await getFileStat(path)
if (!stat) return 0
return stat.size || 0
/**
* Get file size
*
* @param {string} path
* @returns {Promise<number>}
*/
module.exports.getFileSize = async (path) => {
return (await getFileStat(path))?.size || 0
}
/**
* Get file mtimeMs
*
* @param {string} path
* @returns {Promise<number>} epoch timestamp
*/
module.exports.getFileMTimeMs = async (path) => {
return (await getFileStat(path))?.mtimeMs || 0
}
module.exports.getFileSize = getFileSize
/**
*