Commit cca0b175 authored by nanahira's avatar nanahira

rollback delete

parent 31c6c3fe
......@@ -78,7 +78,7 @@ export class SMBReader {
const insertedFileID: number = fileMetadata.insertId;
const previousFilenameArray: any[] = await this.db.query("select filename from `filesRead` where fileid = ?", [insertedFileID - 1]);
let currentMessages = readChatBuffer((await this.smb.readFile(filePath)) as Buffer);
if (previousFilenameArray.length && files.find(f => f.name === previousFilenameArray[0].filename)) {
if (previousFilenameArray.length && files.find(f => f.name === previousFilenameArray[0].filename)) { // compare with old file
const previousFilePath = this.getFilePath(previousFilenameArray[0].filename);
console.error(`${this.logPrefix}Comparing file ${filePath} with old file ${previousFilePath}.`)
try {
......@@ -101,6 +101,16 @@ export class SMBReader {
...message
});
}
const deleteFilenameArray: any[] = await this.db.query("select filename from `filesRead` where fileid = ?", [insertedFileID - 2]);
if (deleteFilenameArray.length && files.find(f => f.name === deleteFilenameArray[0].filename)) { // delete file with id - 2 because useless
const deleteFilePath = this.getFilePath(deleteFilenameArray[0].filename);
try {
console.error(`${this.logPrefix}Deleting file ${deleteFilePath}.`);
await this.smb.unlink(deleteFilePath);
} catch (e) {
console.error(`${this.logPrefix}Failed deleting file ${deleteFilePath}:`, e.toString());
}
}
} catch (e) {
console.error(`${this.logPrefix}Errored reading file ${filePath}:`, e.toString());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment