single maps deletion finished

This commit is contained in:
MathieuG-P
2022-11-28 21:13:57 +01:00
parent c172b1ed81
commit eec011d9f0
2 changed files with 20 additions and 5 deletions
@@ -6,7 +6,7 @@ import { BSLocalVersionService } from "../bs-local-version.service";
import { InstallationLocationService } from "../installation-location.service";
import { UtilsService } from "../utils.service";
import crypto from "crypto";
import { lstat, lstatSync, symlinkSync, readdir, fstat, unlinkSync } from "fs";
import { lstatSync, symlinkSync, unlinkSync, readdirSync } from "fs";
import { copySync } from "fs-extra";
export class LocalMapsManagerService {
@@ -128,7 +128,22 @@ export class LocalMapsManagerService {
}
public async deleteMaps(maps: BsmLocalMap[], verion?: BSVersion){
// TODO
const mapsFolder = await this.getMapsFolderPath(verion);
const mapsHashsToDelete = maps.map(m => m.hash);
const mapsFolders = readdirSync(mapsFolder, {withFileTypes: true});
for(const content of mapsFolders){
if(!content.isDirectory()){ continue; }
const mapFolderPath = path.join(mapsFolder, content.name);
const { hash } = await this.loadMapInfoFromPath(mapFolderPath);
if(mapsHashsToDelete.includes(hash)){
await this.utils.deleteFolder(mapFolderPath);
}
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
import { existsSync, mkdirSync, readdirSync, readFile, unlinkSync } from "fs";
import { existsSync, mkdirSync, readdirSync, readFile, rmSync } from "fs";
import { moveSync } from "fs-extra"
import { spawnSync } from "child_process";
import { homedir } from "os";
@@ -75,10 +75,10 @@ export class UtilsService{
return files.map(f => fullPath ? path.join(dirPath, f.name) : f.name);
}
public deleteFolder(folderPath: string): Promise<void>{
public async deleteFolder(folderPath: string): Promise<void>{
const folderExist = this.pathExist(folderPath);
if(!folderExist){ return; }
return rm(folderPath, {recursive: true});
return rmSync(folderPath, {recursive: true});
}
public async moveDirContent(src: string, dest: string, overwrite = false): Promise<void>{