Skip to content

Commit

Permalink
refactor(archive-manager): switch to plain tar usage
Browse files Browse the repository at this point in the history
  • Loading branch information
meienberger committed Oct 19, 2024
1 parent fa754bb commit 0f15c4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 3 additions & 9 deletions packages/shared/src/node/modules/archive/archive-manager.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import fs from 'node:fs';
import gunzip from 'gunzip-maybe';
import { extract, pack } from 'tar-fs';
import { execAsync } from 'src/node/helpers/exec-async';

export class ArchiveManager {
createTarGz = async (sourceDir: string, destinationFile: string) => {
return new Promise<void>((resolve, reject) => {
pack(sourceDir).pipe(gunzip()).pipe(fs.createWriteStream(destinationFile)).on('finish', resolve).on('error', reject);
});
return execAsync(`tar -czf ${destinationFile} -C ${sourceDir} .`);
};

extractTarGz = async (sourceFile: string, destinationDir: string) => {
return new Promise<void>((resolve, reject) => {
fs.createReadStream(sourceFile).pipe(gunzip()).pipe(extract(destinationDir)).on('finish', resolve).on('error', reject);
});
return execAsync(`tar -xzf ${sourceFile} -C ${destinationDir}`);
};
}
10 changes: 8 additions & 2 deletions packages/shared/src/node/modules/backup/backup-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export class BackupManager {
this.logger.info('Creating archive...');

// Create the archive
await this.archiveManager.createTarGz(tempDir, `${path.join(tempDir, backupName)}.tar.gz`);
const { stdout, stderr } = await this.archiveManager.createTarGz(tempDir, `${path.join(tempDir, backupName)}.tar.gz`);
this.logger.debug('--- archiveManager.createTarGz ---');
this.logger.debug('stderr:', stderr);
this.logger.debug('stdout:', stdout);

this.logger.info('Moving archive to backup directory...');

Expand Down Expand Up @@ -73,7 +76,10 @@ export class BackupManager {
await fs.promises.mkdir(restoreDir, { recursive: true });

this.logger.info('Extracting archive...');
await this.archiveManager.extractTarGz(archive, restoreDir);
const { stderr, stdout } = await this.archiveManager.extractTarGz(archive, restoreDir);
this.logger.debug('--- archiveManager.extractTarGz ---');
this.logger.debug('stderr:', stderr);
this.logger.debug('stdout:', stdout);

const appDataDirPath = path.join(this.appDataDir, appId);
const appDirPath = path.join(this.dataDir, 'apps', appId);
Expand Down

0 comments on commit 0f15c4e

Please sign in to comment.