diff --git a/.gitignore b/.gitignore
index c0204e896..dab4da2fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,7 @@ output/
input/
*.heapsnapshot
qbit/
+docker/
cache.json
docker-compose.yml
utils.zsh
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index f13e4aab1..3d869cecd 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -61,5 +61,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/action.ts b/src/action.ts
index 974b10e73..f12074d45 100644
--- a/src/action.ts
+++ b/src/action.ts
@@ -7,7 +7,7 @@ import {
statSync,
symlinkSync,
} from "fs";
-import path from "path";
+import { join, resolve, dirname, basename } from "path";
import { getClient } from "./clients/TorrentClient.js";
import {
Action,
@@ -48,21 +48,19 @@ export async function performAction(
} else if (decision == Decision.MATCH_SIZE_ONLY) {
// Size only matching is only supported for single file or
// single, nested file torrents.
- const candidateParentDir = path.dirname(newMeta.files[0].path);
+ const candidateParentDir = dirname(newMeta.files[0].path);
let correctedlinkDir = linkDir;
// Candidate is single, nested file
- if (candidateParentDir != ".") {
- if (!existsSync(path.join(linkDir, candidateParentDir))) {
- mkdirSync(path.join(linkDir, candidateParentDir), {
- recursive: true,
- });
- }
- correctedlinkDir = path.join(linkDir, candidateParentDir);
+ if (candidateParentDir !== ".") {
+ mkdirSync(join(linkDir, candidateParentDir), {
+ recursive: true,
+ });
+ correctedlinkDir = join(linkDir, candidateParentDir);
}
linkFile(
searchee.path,
- path.join(correctedlinkDir, newMeta.files[0].name)
+ join(correctedlinkDir, newMeta.files[0].name)
);
}
}
@@ -125,32 +123,29 @@ function linkExact(oldPath: string, newPath: string) {
return;
}
if (statSync(oldPath).isFile()) {
- if (!existsSync(path.join(newPath, path.basename(oldPath)))) {
- linkFile(oldPath, path.join(newPath, path.basename(oldPath)));
+ if (!existsSync(join(newPath, basename(oldPath)))) {
+ linkFile(oldPath, join(newPath, basename(oldPath)));
}
return;
}
-
- try {
- mkdirSync(path.join(newPath, path.basename(oldPath)));
- } catch (e) {
- // skip if it already exists
- }
+ mkdirSync(join(newPath, basename(oldPath)), { recursive: true });
readdirSync(oldPath).forEach((file) => {
- linkExact(
- path.join(oldPath, file),
- path.join(newPath, path.basename(oldPath))
- );
+ linkExact(join(oldPath, file), join(newPath, basename(oldPath)));
});
}
function linkFile(oldPath: string, newPath: string) {
const { linkType } = getRuntimeConfig();
- if (existsSync(newPath)) return;
-
- if (linkType === LinkType.HARDLINK) {
- linkSync(oldPath, newPath);
- } else {
- symlinkSync(oldPath, newPath);
+ try {
+ if (linkType === LinkType.HARDLINK) {
+ linkSync(oldPath, newPath);
+ } else {
+ // we need to resolve because symlinks are resolved outside
+ // the context of cross-seed's working directory
+ symlinkSync(oldPath, resolve(newPath));
+ }
+ } catch (e) {
+ if (e.code === "EEXIST") return;
+ throw e;
}
}