mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[hotfix] When clone version, copy junction link and not copy their content
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user