Work with two dirs

This commit is contained in:
Benjamin Bädorf 2023-01-25 23:36:55 +01:00
parent c376899d81
commit 5577aaa159
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C

View file

@ -1,36 +1,40 @@
(async () => {
const dir = '/home/ben/Nextcloud';
import { join } from "https://deno.land/std@0.173.0/path/mod.ts";
const DRY_RUN = false;
(async () => {
const mainDir = '/home/ben/Nextcloud';
const backupDir = '/home/ben/Nextcloud.bak';
const DRY_RUN = true;
const BATCH_SIZE = 16;
const ENCRYPTED_CONTENT_STRING = 'HBEGIN:oc_encryption_module:OC_DEFAULT_MODULE:cipher';
const CONFLICTED_COPY_REGEX = /.*( \(conflicted copy \d{4}-\d{2}-\d{2} \d+\))(\.[^\.]*)?/;
const p = Deno.run({
cmd: ['bash', '-c', `find ${dir} -type f | grep conflicted\\ copy`],
cmd: ['bash', '-c', `find . -type f | grep conflicted\\ copy`],
stdout: 'piped',
cwd: backupDir
});
const output = await p.output();
p.close();
const outputStr = (new TextDecoder()).decode(output);
const fileNames = [...new Set(outputStr.split('\n').filter(s => !!s))];
const fileNames = [...new Set(outputStr.split('\n').filter(s => !!s))].map(s => join(backupDir, s));
const totalFiles = fileNames.length;
let filesSuccess = 0;
let fileData = [];
let fileData: string[] = [];
for (let i = 0; i < totalFiles; i += BATCH_SIZE) {
fileData = [
...fileData,
...(await Promise.all(fileNames.slice(i, i + BATCH_SIZE).map(async (conflictedFileName, index) => {
...(await Promise.all(fileNames.slice(i, i + BATCH_SIZE).map(async (conflictedFileName) => {
const conflictedNameMatch = conflictedFileName.match(CONFLICTED_COPY_REGEX);
if (!conflictedNameMatch) {
return `[${conflictedFileName}] encountered regex error`;
}
const conflictString = conflictedNameMatch[1];
const nonConflictedFileName = conflictedFileName.replace(conflictString, '');
const nonConflictedFileName = join(mainDir, conflictedFileName.replace(conflictString, ''));
const conflictedFile = await Deno.open(conflictedFileName, { read: true });
const conflictedFileInfo = await Deno.fstat(conflictedFile.rid);