Skip to content

Commit 6edb8cf

Browse files
committed
G4E-9715 Storing files with hash suffix to prevent issues with files case insensitive naming on windows
1 parent 675c297 commit 6edb8cf

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/layouts/layouts.service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
22
import { promisify } from "util";
33
import { readdir, readFile, writeFile, unlink, existsSync } from "fs";
44
import { join } from "path";
5+
import { createHash } from "crypto";
56
import * as json5 from "json5";
67
import { SaveLayoutRequestDto } from './dto/save-layout-request.dto';
78
import { LayoutDto } from './dto/layout.dto';
@@ -21,7 +22,7 @@ const unlinkFilePromisified = promisify(unlink);
2122
export class FileBasedLayoutsService {
2223

2324

24-
private layoutsFolder = process.env.LAYOUTS_FOLDER || "./configuration/layouts";
25+
private layoutsFolder = process.env.LAYOUTS_FOLDER || "./configuration/layouts";
2526
private defaultLayoutType = "default";
2627

2728
async getAll(): Promise<LayoutDto[]> {
@@ -83,15 +84,17 @@ export class FileBasedLayoutsService {
8384
console.error("Error deleting old layout file:", error);
8485
}
8586

86-
layout.name = newName;
87-
await this.saveLayout(layout);
88-
}
87+
layout.name = newName;
88+
await this.saveLayout(layout);
89+
}
8990

9091
getLayoutPath(layout: LayoutDto): string {
9192
return join(this.layoutsFolder, this.getLayoutName(layout));
9293
}
9394

9495
getLayoutName(layout: LayoutDto): string {
95-
return `${layout.type}-${layout.name}.json`;
96+
// Hash is appended to avoid conflicts due to NTFS case-insensitive file naming on Windows.
97+
const hash = createHash("sha256").update(layout.name).digest("hex").slice(0, 8);
98+
return `${layout.type}-${layout.name}_${hash}.json`;
9699
}
97100
}

0 commit comments

Comments
 (0)