Merge pull request #189 from Zagrios/hotfix/not-clone-link-content-when-clone-version

[hotfix] when clonning, contents of linked folder no longer duplicate
This commit is contained in:
MathieuG-P
2023-03-20 00:31:05 +01:00
committed by GitHub
2 changed files with 24 additions and 4 deletions
+22 -1
View File
@@ -1,4 +1,4 @@
import { move } from "fs-extra";
import { copyFile, ensureDir, move, symlink } from "fs-extra";
import { access, mkdir, rm, readdir, unlink, lstat, readlink } from "fs/promises";
import path from "path";
import { Observable } from "rxjs";
@@ -81,6 +81,27 @@ export function moveFolderContent(src: string, dest: string): Observable<Progres
});
}
export async function copyDirectoryWithJunctions(source: string, destination: string): Promise<void> {
await ensureDir(destination);
const items = await readdir(source);
for (const item of items) {
const sourcePath = path.join(source, item);
const destinationPath = path.join(destination, item);
const stats = await lstat(sourcePath);
if (stats.isDirectory()) {
await copyDirectoryWithJunctions(sourcePath, destinationPath);
} else if (stats.isFile()) {
await copyFile(sourcePath, destinationPath);
} else if (stats.isSymbolicLink()) {
const symlinkTarget = await readlink(sourcePath);
await symlink(symlinkTarget, destinationPath, "junction");
}
}
}
export interface Progression<T = unknown>{
total: number;
current: number;
@@ -5,7 +5,6 @@ import { SteamService } from "./steam.service";
import { BS_APP_ID, OCULUS_BS_DIR } from "../constants";
import path from "path";
import { createReadStream } from "fs";
import fs from "fs-extra";
import { ConfigurationService } from "./configuration.service";
import { rename } from "fs/promises";
import { BsmException } from "shared/models/bsm-exception.model";
@@ -13,7 +12,7 @@ import log from "electron-log";
import { OculusService } from "./oculus.service";
import { DownloadLinkType } from "shared/models/mods";
import sanitize from "sanitize-filename";
import { deleteFolder, getFoldersInFolder, pathExist } from "../helpers/fs.helpers";
import { copyDirectoryWithJunctions, deleteFolder, getFoldersInFolder, pathExist } from "../helpers/fs.helpers";
import { FolderLinkerService } from "./folder-linker.service";
export class BSLocalVersionService{
@@ -223,7 +222,7 @@ export class BSLocalVersionService{
if(await pathExist(newPath)){ throw {title: "VersionAlreadExist"} as BsmException; }
return fs.copy(originPath, newPath, {dereference: true}).then(() => {
return copyDirectoryWithJunctions(originPath, newPath).then(() => {
this.addCustomVersion(cloneVersion);
return cloneVersion;
}).catch((err: Error) => {