Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/src/store/listeners/config-listener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync } from 'fs';
import { writeFile } from 'fs/promises';

import type { ConfigType } from '@app/core/utils/files/config-file-normalizer.js';
import { logger } from '@app/core/log.js';
Expand All @@ -17,6 +17,6 @@ export const enableConfigFileListener = (mode: ConfigType) => () =>
const writeableConfig = getWriteableConfig(config, mode);
const serializedConfig = safelySerializeObjectToIni(writeableConfig);
logger.debug('Writing updated config to %s', pathToWrite);
writeFileSync(pathToWrite, serializedConfig);
await writeFile(pathToWrite, serializedConfig);
},
});
5 changes: 2 additions & 3 deletions api/src/store/modules/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { F_OK } from 'constants';
import { writeFileSync } from 'fs';
import { access } from 'fs/promises';
import { access, writeFile } from 'fs/promises';

import type { PayloadAction } from '@reduxjs/toolkit';
import { createAsyncThunk, createSlice, isAnyOf } from '@reduxjs/toolkit';
Expand Down Expand Up @@ -140,7 +139,7 @@ export const loadConfigFile = createAsyncThunk<
const newConfig = getWriteableConfig(initialState, 'flash');
newConfig.remote.wanaccess = 'no';
const serializedConfig = safelySerializeObjectToIni(newConfig);
writeFileSync(getState().paths['myservers-config'], serializedConfig);
await writeFile(getState().paths['myservers-config'], serializedConfig);
return rejectWithValue({
type: CONFIG_LOAD_ERROR.CONFIG_CORRUPTED,
error: error instanceof Error ? error : new Error('Unknown Error'),
Expand Down
4 changes: 2 additions & 2 deletions api/src/unraid-api/cli/pm2.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable } from '@nestjs/common';
import { existsSync } from 'node:fs';
import { mkdir, rm } from 'node:fs/promises';
import { join } from 'node:path';

import type { Options, Result, ResultPromise } from 'execa';
import { execa, ExecaError } from 'execa';

import { fileExists } from '@app/core/utils/files/file-exists.js';
import { LOGS_DIR, PM2_HOME, PM2_PATH } from '@app/environment.js';
import { LogService } from '@app/unraid-api/cli/log.service.js';

Expand Down Expand Up @@ -90,7 +90,7 @@ export class PM2Service {
}

async deletePm2Home() {
if (existsSync(PM2_HOME) && existsSync(join(PM2_HOME, 'pm2.log'))) {
if ((await fileExists(PM2_HOME)) && (await fileExists(join(PM2_HOME, 'pm2.log')))) {
await rm(PM2_HOME, { recursive: true, force: true });
this.logger.trace('PM2 home directory cleared.');
} else {
Expand Down
4 changes: 2 additions & 2 deletions api/src/unraid-api/graph/resolvers/display/display.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable } from '@nestjs/common';
import { existsSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';

import { type DynamixConfig } from '@app/core/types/ini.js';
import { toBoolean } from '@app/core/utils/casting.js';
import { fileExists } from '@app/core/utils/files/file-exists.js';
import { loadState } from '@app/core/utils/misc/load-state.js';
import { getters } from '@app/store/index.js';
import { ThemeName } from '@app/unraid-api/graph/resolvers/customization/theme.model.js';
Expand Down Expand Up @@ -80,7 +80,7 @@ export class DisplayService {

// If the config file doesn't exist then it's a new OS install
// Default to "default"
if (!existsSync(configFilePath)) {
if (!(await fileExists(configFilePath))) {
return states.default;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable, Logger } from '@nestjs/common';
import { statSync } from 'fs';
import { readdir, rename, unlink, writeFile } from 'fs/promises';
import { readdir, rename, stat, unlink, writeFile } from 'fs/promises';
import { basename, join } from 'path';

import type { Stats } from 'fs';
Expand Down Expand Up @@ -581,12 +580,15 @@ export class NotificationsService {
sortFn: SortFn<Stats> = (fileA, fileB) => fileB.birthtimeMs - fileA.birthtimeMs // latest first
): Promise<string[]> {
const contents = narrowContent(await readdir(folderPath));
return contents
.map((content) => {
const contentStats = await Promise.all(
contents.map(async (content) => {
// pre-map each file's stats to avoid excess calls during sorting
const path = join(folderPath, content);
return { path, stats: statSync(path) };
const stats = await stat(path);
return { path, stats };
})
);
return contentStats
.sort((fileA, fileB) => sortFn(fileA.stats, fileB.stats))
.map(({ path }) => path);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable, Logger, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import crypto from 'crypto';
import { ChildProcess } from 'node:child_process';
import { existsSync } from 'node:fs';
import { mkdir, rm, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';

Expand All @@ -10,6 +9,7 @@ import got, { HTTPError } from 'got';
import pRetry from 'p-retry';

import { sanitizeParams } from '@app/core/log.js';
import { fileExists } from '@app/core/utils/files/file-exists.js';
import {
CreateRCloneRemoteDto,
DeleteRCloneRemoteDto,
Expand Down Expand Up @@ -104,7 +104,7 @@ export class RCloneApiService implements OnModuleInit, OnModuleDestroy {
private async startRcloneSocket(socketPath: string, logFilePath: string): Promise<boolean> {
try {
// Make log file exists
if (!existsSync(logFilePath)) {
if (!(await fileExists(logFilePath))) {
this.logger.debug(`Creating log file: ${logFilePath}`);
await mkdir(dirname(logFilePath), { recursive: true });
await writeFile(logFilePath, '', 'utf-8');
Expand Down Expand Up @@ -187,7 +187,7 @@ export class RCloneApiService implements OnModuleInit, OnModuleDestroy {
}

// Clean up the socket file if it exists
if (this.rcloneSocketPath && existsSync(this.rcloneSocketPath)) {
if (this.rcloneSocketPath && (await fileExists(this.rcloneSocketPath))) {
this.logger.log(`Removing RClone socket file: ${this.rcloneSocketPath}`);
try {
await rm(this.rcloneSocketPath, { force: true });
Expand All @@ -201,7 +201,7 @@ export class RCloneApiService implements OnModuleInit, OnModuleDestroy {
* Checks if the RClone socket exists
*/
private async checkRcloneSocketExists(socketPath: string): Promise<boolean> {
const socketExists = existsSync(socketPath);
const socketExists = await fileExists(socketPath);
if (!socketExists) {
this.logger.warn(`RClone socket does not exist at: ${socketPath}`);
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync } from 'fs';
import { readFile } from 'fs/promises';
import { join } from 'node:path';

import { fileExists } from '@app/core/utils/files/file-exists.js';
import {
FileModification,
ShouldApplyWithReason,
Expand Down Expand Up @@ -45,7 +45,7 @@ export default class AuthRequestModification extends FileModification {

const filesToAdd = [getters.paths().webgui.logo.assetPath, ...jsFiles];

if (!existsSync(this.filePath)) {
if (!(await fileExists(this.filePath))) {
throw new Error(`File ${this.filePath} not found.`);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync } from 'fs';
import { readFile } from 'fs/promises';

import { fileExists } from '@app/core/utils/files/file-exists.js';
import {
FileModification,
ShouldApplyWithReason,
Expand All @@ -25,7 +25,7 @@ export default class RcNginxModification extends FileModification {
* @returns The patch for the rc.nginx file
*/
protected async generatePatch(overridePath?: string): Promise<string> {
if (!existsSync(this.filePath)) {
if (!(await fileExists(this.filePath))) {
throw new Error(`File ${this.filePath} not found.`);
}
const fileContent = await readFile(this.filePath, 'utf8');
Expand Down