Skip to content

Commit

Permalink
chore: refactor directory creation code, add required dirs
Browse files Browse the repository at this point in the history
Signed-off-by: Iliya Savov <isavov@users.noreply.github.com>
  • Loading branch information
isavov committed Jan 3, 2024
1 parent 9d5c5f9 commit 4f8dfee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/state/InitState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ export class InitState implements IState{

private prepareWorkDirectory() {
this.logger.info(`Local Node Working directory set to ${this.cliOptions.workDir}`, this.stateName);

FileSystemUtils.ensureDirectoryExists(this.cliOptions.workDir);
FileSystemUtils.ensureDirectoryExists(join(this.cliOptions.workDir, 'network-logs', 'node', 'logs')); //creating those directories ensures we'll have permissions to delete them on cleanup
FileSystemUtils.ensureDirectoryExists(join(this.cliOptions.workDir, 'network-logs', 'node', 'recordStreams','record0.0.3','sidecar'));

FileSystemUtils.createEphemeralDirectories(this.cliOptions.workDir);
const configDirSource = join(__dirname, '../../compose-network/network-node/data/config/');
const configPathMirrorNodeSource = join(__dirname, APPLICATION_YML_RELATIVE_PATH);
const recordParserSource = join(__dirname,'../../src/services/record-parser');
Expand Down
12 changes: 12 additions & 0 deletions src/utils/FileSystemUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,16 @@ export class FileSystemUtils{
// else it's Linux
return join(process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'), name);
}

public static createEphemeralDirectories(workDir: string) {
const directories = [
workDir,
join(workDir, 'network-logs', 'node', 'accountBalances', 'balance0.0.3'),
join(workDir, 'network-logs', 'node', 'recordStreams', 'record0.0.3', 'sidecar'),
join(workDir, 'network-logs', 'node', 'logs'),
join(workDir, 'network-logs', 'node', 'stats'),
];

directories.forEach(dir => FileSystemUtils.ensureDirectoryExists(dir)); //creating those directories ensures we'll have permissions to delete them on cleanup
}
}

0 comments on commit 4f8dfee

Please sign in to comment.