mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[bugfix] Improve folder linking reliability
This commit is contained in:
@@ -4,6 +4,8 @@ import { deleteFolder, ensureFolderExist, moveFolderContent, pathExist, unlinkPa
|
||||
import { lstat, symlink } from "fs/promises";
|
||||
import path from "path";
|
||||
import { copy, readlink } from "fs-extra";
|
||||
import { lastValueFrom } from "rxjs";
|
||||
import { noop } from "shared/helpers/function.helpers";
|
||||
|
||||
export class FolderLinkerService {
|
||||
private static instance: FolderLinkerService;
|
||||
@@ -72,7 +74,7 @@ export class FolderLinkerService {
|
||||
await ensureFolderExist(folderPath);
|
||||
|
||||
if (options?.keepContents !== false) {
|
||||
await moveFolderContent(folderPath, sharedPath).toPromise();
|
||||
await lastValueFrom(moveFolderContent(folderPath, sharedPath, { overwrite: true }));
|
||||
}
|
||||
|
||||
await deleteFolder(folderPath);
|
||||
@@ -95,9 +97,7 @@ export class FolderLinkerService {
|
||||
}
|
||||
|
||||
if (options.moveContents === true) {
|
||||
return moveFolderContent(sharedPath, folderPath)
|
||||
.toPromise()
|
||||
.then(() => {});
|
||||
return lastValueFrom(moveFolderContent(sharedPath, folderPath, { overwrite: true })).then(noop);
|
||||
}
|
||||
|
||||
if (options?.keepContents === false) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getFoldersInFolder } from "../helpers/fs.helpers";
|
||||
import path from "path";
|
||||
import { VersionLinkerAction, VersionLinkFolderAction, VersionUnlinkFolderAction } from "renderer/services/version-folder-linker.service";
|
||||
import { VersionLinkerAction, VersionUnlinkFolderAction } from "renderer/services/version-folder-linker.service";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
import { LocalMapsManagerService } from "./additional-content/maps/local-maps-manager.service";
|
||||
import { BSLocalVersionService } from "./bs-local-version.service";
|
||||
@@ -58,17 +58,14 @@ export class VersionFolderLinkerService {
|
||||
return path.join(parentPath, relativePath);
|
||||
}
|
||||
|
||||
public async linkVersionFolder(action: VersionLinkerAction): Promise<boolean> {
|
||||
public async linkVersionFolder(action: VersionLinkerAction): Promise<void> {
|
||||
action.options = this.specialFolderOption(action.relativeFolder, action.options);
|
||||
const versionPath = await this.localVersion.getVersionPath(action.version);
|
||||
const folderPath = this.relativeToFullPath(versionPath, action.relativeFolder);
|
||||
return this.folderLinker
|
||||
.linkFolder(folderPath, action.options)
|
||||
.catch(() => false)
|
||||
.then(() => true);
|
||||
return this.folderLinker.linkFolder(folderPath, action.options)
|
||||
}
|
||||
|
||||
public async unlinkVersionFolder(action: VersionUnlinkFolderAction): Promise<boolean> {
|
||||
public async unlinkVersionFolder(action: VersionUnlinkFolderAction): Promise<void> {
|
||||
action.options = this.specialFolderOption(action.relativeFolder, action.options);
|
||||
|
||||
const versionPath = await this.localVersion.getVersionPath(action.version);
|
||||
@@ -76,13 +73,10 @@ export class VersionFolderLinkerService {
|
||||
|
||||
action.options.moveContents = !(await this.isOtherVersionHaveFolderLinked(action.relativeFolder, folderPath));
|
||||
|
||||
return this.folderLinker
|
||||
.unlinkFolder(folderPath, action.options)
|
||||
.catch(() => false)
|
||||
.then(() => true);
|
||||
return this.folderLinker.unlinkFolder(folderPath, action.options);
|
||||
}
|
||||
|
||||
public async doAction(action: VersionLinkerAction): Promise<boolean> {
|
||||
public doAction(action: VersionLinkerAction): Promise<void> {
|
||||
if (action.type === "link") {
|
||||
return this.linkVersionFolder(action);
|
||||
}
|
||||
@@ -123,7 +117,7 @@ export class VersionFolderLinkerService {
|
||||
|
||||
for (const version of versions) {
|
||||
const linkedFolders = await this.getLinkedFolders(version, { relative: true, ignoreSymlinkTargetError: true });
|
||||
const actions = linkedFolders.map(folder => ({ type: "link", version, relativeFolder: folder } as VersionLinkFolderAction));
|
||||
const actions = linkedFolders.map(folder => ({ type: "link", version, relativeFolder: folder } as VersionLinkerAction));
|
||||
await Promise.all(actions.map(action => this.doAction(action)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user