Fix cross-device rename

This commit is contained in:
Evert Prants 2018-10-18 18:15:33 +03:00
parent 37760f5639
commit 051f95fee7
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 14 additions and 2 deletions

View File

@ -72,4 +72,15 @@ function askAsync (rl, q) {
}) })
} }
export default {getFiles, promiseExec, askAsync, insertDB} function copyAsync (fsrc, fdst) {
return new Promise((resolve, reject) => {
let source = fs.createReadStream(path.resolve(fsrc))
let dest = fs.createWriteStream(path.resolve(fdst))
source.pipe(dest)
source.on('end', resolve)
source.on('error', reject)
})
}
export default {getFiles, promiseExec, askAsync, insertDB, copyAsync}

View File

@ -49,7 +49,8 @@ async function download (furl) {
} }
let fn = path.join(musicdir, filename) let fn = path.join(musicdir, filename)
await fs.rename(file.source, fn) await asn.copyAsync(file.source, fn)
await fs.unlink(file.source)
let id3 = await asn.promiseExec(`id3 -a "${clean.artist}" -t "${clean.title}" "${fn}"`) let id3 = await asn.promiseExec(`id3 -a "${clean.artist}" -t "${clean.title}" "${fn}"`)