1- import { mkdir , lstat , readdir , chown } from 'fs/promises'
1+ import { lstat , readdir } from 'fs/promises'
22import { join , sep } from 'path/posix'
3- import { copy , pathExists } from 'fs-extra'
3+ import { copy } from 'fs-extra'
44import { BackupRecord , BackupType , Directory , FileData , RecordTable } from '../common/types.js'
55import { v4 as uuid } from 'uuid'
66import {
@@ -10,10 +10,9 @@ import {
1010 IOException
1111} from '../common/exceptions.js'
1212import { DatabaseManager } from './database.js'
13- import { log } from './logger.js'
1413import { createHash } from 'crypto'
15- import { createReadStream , MakeDirectoryOptions , ReadStream } from 'fs'
16- import { compareByDepth } from '../common/functions.js'
14+ import { createReadStream , ReadStream } from 'fs'
15+ import { compareByDepth , createDirectory } from '../common/functions.js'
1716
1817export class BackupManager {
1918 private static instance : BackupManager
@@ -32,32 +31,6 @@ export class BackupManager {
3231 return BackupManager . instance
3332 }
3433
35- private async _createDirectory (
36- rootPath : string ,
37- directoryName : string ,
38- options : MakeDirectoryOptions = { mode : '0755' } ,
39- ownership ?: { uid : number ; gid : number }
40- ) : Promise < [ string , Error ] > {
41- try {
42- const fullPath = join ( rootPath , directoryName )
43- if ( ! await pathExists ( fullPath ) ) {
44- await mkdir ( fullPath , { recursive : false , ...options } )
45-
46- // Append ownership information to directory
47- if ( ownership ) await chown ( fullPath , ownership . uid , ownership . gid )
48- return [ fullPath , null ]
49- } else {
50- log ( `Directory already exists ... skipping create.` )
51- return [ fullPath , null ]
52- }
53- } catch ( err ) {
54- if ( ! err . message . includes ( 'EPERM' ) ) {
55- log ( `ERROR creating directory: ${ err } ` )
56- return [ null , err ]
57- }
58- }
59- }
60-
6134 public clearBuffers ( ) : void {
6235 this . filesBuffer = [ ]
6336 this . directoriesBuffer = [ ]
@@ -296,7 +269,7 @@ export class BackupManager {
296269
297270 // Append the operation to the queue
298271 processQueue . push (
299- this . _createDirectory (
272+ createDirectory (
300273 destRoot ,
301274 d . path . split ( sourceRoot ) [ 1 ] ,
302275 { mode : d . mode || '0755' } ,
@@ -351,7 +324,7 @@ export class BackupManager {
351324 }
352325
353326 // Make the backup directory && Copy all changed files (maintaining path and timestamps)
354- const [ _ , createErr ] = await this . _createDirectory ( destination , generatedBackupName )
327+ const [ _ , createErr ] = await createDirectory ( destination , generatedBackupName )
355328 if ( createErr ) {
356329 throw new IOException ( `Could not create the backup directory. Aborting... (${ createErr . message } )` )
357330 }
@@ -418,7 +391,7 @@ export class BackupManager {
418391 }
419392
420393 // Create the FULL backup
421- const [ _ , createErr ] = await this . _createDirectory ( destination , generatedBackupName )
394+ const [ _ , createErr ] = await createDirectory ( destination , generatedBackupName )
422395 if ( createErr ) {
423396 throw new IOException ( `Could not create the backup directory. Aborting... (${ createErr . message } )` )
424397 }
0 commit comments