Work with two dirs
This commit is contained in:
parent
c376899d81
commit
5577aaa159
|
@ -1,36 +1,40 @@
|
||||||
(async () => {
|
import { join } from "https://deno.land/std@0.173.0/path/mod.ts";
|
||||||
const dir = '/home/ben/Nextcloud';
|
|
||||||
|
|
||||||
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 BATCH_SIZE = 16;
|
||||||
const ENCRYPTED_CONTENT_STRING = 'HBEGIN:oc_encryption_module:OC_DEFAULT_MODULE:cipher';
|
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 CONFLICTED_COPY_REGEX = /.*( \(conflicted copy \d{4}-\d{2}-\d{2} \d+\))(\.[^\.]*)?/;
|
||||||
|
|
||||||
const p = Deno.run({
|
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',
|
stdout: 'piped',
|
||||||
|
cwd: backupDir
|
||||||
});
|
});
|
||||||
|
|
||||||
const output = await p.output();
|
const output = await p.output();
|
||||||
p.close();
|
p.close();
|
||||||
|
|
||||||
const outputStr = (new TextDecoder()).decode(output);
|
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;
|
const totalFiles = fileNames.length;
|
||||||
let filesSuccess = 0;
|
let filesSuccess = 0;
|
||||||
let fileData = [];
|
let fileData: string[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < totalFiles; i += BATCH_SIZE) {
|
for (let i = 0; i < totalFiles; i += BATCH_SIZE) {
|
||||||
fileData = [
|
fileData = [
|
||||||
...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);
|
const conflictedNameMatch = conflictedFileName.match(CONFLICTED_COPY_REGEX);
|
||||||
if (!conflictedNameMatch) {
|
if (!conflictedNameMatch) {
|
||||||
return `[${conflictedFileName}] encountered regex error`;
|
return `[${conflictedFileName}] encountered regex error`;
|
||||||
}
|
}
|
||||||
const conflictString = conflictedNameMatch[1];
|
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 conflictedFile = await Deno.open(conflictedFileName, { read: true });
|
||||||
const conflictedFileInfo = await Deno.fstat(conflictedFile.rid);
|
const conflictedFileInfo = await Deno.fstat(conflictedFile.rid);
|
||||||
|
|
Loading…
Reference in a new issue