Skip to content

Commit

Permalink
fix: Handling file extension for duplicate files
Browse files Browse the repository at this point in the history
  • Loading branch information
steilerDev committed Oct 2, 2023
1 parent 28123f3 commit 0228fcf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/src/lib/resources/network-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export class NetworkManager {
.catch(() => false);

if (fileExists) {
const fileName = path.basename(location);
const file = path.parse(location);
const duplicateFolder = path.join(Resources.manager().dataDir, `duplicates`);
const duplicateFolderExists = await fs.stat(duplicateFolder)
.then(stat => stat.isDirectory())
Expand All @@ -516,15 +516,15 @@ export class NetworkManager {
await fs.mkdir(duplicateFolder);
}

const origFileName = fileName + `-orig`;
const origFileName = file.name + `-orig` + file.ext;
const origFileLinked = await fs.lstat(path.join(duplicateFolder, origFileName))
.then(stat => stat.isSymbolicLink())
.catch(() => false);
if (!origFileLinked) {
await fs.link(location, path.join(duplicateFolder, origFileName));
}

const duplicateFileName = fileName + `-dup-` + randomInt(0, 1000000).toString();
const duplicateFileName = file.name + `-dup-` + randomInt(0, 1000000).toString() + file.ext;

location = path.join(duplicateFolder, duplicateFileName);
Resources.logger(this).warn(`${location} already exists - saving duplicate to ${location} and linking original file ${origFileName} to ${duplicateFolder}`);
Expand Down

0 comments on commit 0228fcf

Please sign in to comment.