fix typos

This commit is contained in:
tdurieux
2021-04-06 17:45:36 +02:00
parent b653f37920
commit cf17e1c456
18 changed files with 66 additions and 68 deletions

View File

@@ -3,7 +3,7 @@ const ofs = require("fs");
const path = require("path");
const fileUtils = require("./file");
const ananymiseContent = (content, repoConfig) => {
const anonymizeContent = (content, repoConfig) => {
const urlRegex = /<?\b((https?|ftp|file):\/\/)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]\b\/?>?/g;
if (repoConfig.options.image === false) {
@@ -54,7 +54,7 @@ const ananymiseContent = (content, repoConfig) => {
return content;
};
const ananymisePath = (path, repoConfig) => {
const anonymizePath = (path, repoConfig) => {
for (let term of repoConfig.terms) {
if (term.trim() == "") {
continue;
@@ -80,13 +80,13 @@ const anonymizeFolder = async (root, destination, repoConfig) => {
for await (const originalFilePath of walk(root)) {
const destinationFilePath = path.join(
destination,
ananymisePath(originalFilePath.replace(root, ""), repoConfig)
anonymizePath(originalFilePath.replace(root, ""), repoConfig)
);
const destinationFolder = path.dirname(destinationFilePath);
if (!ofs.existsSync(destinationFolder)) {
await fs.mkdir(destinationFolder, { recursive: true });
}
await ananymiseFile(originalFilePath, destinationFilePath, repoConfig);
await anonymizeFile(originalFilePath, destinationFilePath, repoConfig);
}
} catch (error) {
fs.rm(destination, { recursive: true, force: true });
@@ -94,12 +94,12 @@ const anonymizeFolder = async (root, destination, repoConfig) => {
}
};
const ananymiseFile = async (filePath, target, repoConfig) => {
const anonymizeFile = async (filePath, target, repoConfig) => {
if (!ofs.existsSync(path.dirname(target))) {
await fs.mkdir(path.dirname(target), { recursive: true });
}
if (fileUtils.isText(filePath)) {
const content = ananymiseContent(
const content = anonymizeContent(
(await fs.readFile(filePath)).toString(),
repoConfig
);
@@ -109,7 +109,7 @@ const ananymiseFile = async (filePath, target, repoConfig) => {
}
};
module.exports.ananymiseFile = ananymiseFile;
module.exports.ananymisePath = ananymisePath;
module.exports.anonymizeFile = anonymizeFile;
module.exports.anonymizePath = anonymizePath;
module.exports.anonymizeFolder = anonymizeFolder;
module.exports.ananymiseContent = ananymiseContent;
module.exports.anonymizeContent = anonymizeContent;

View File

@@ -201,7 +201,7 @@ function anonymizeTree(tree, repoConfig) {
}
const output = {};
for (let file in tree.child) {
const anonymizedPath = anonymizeUtils.ananymisePath(file, repoConfig);
const anonymizedPath = anonymizeUtils.anonymizePath(file, repoConfig);
output[anonymizedPath] = anonymizeTree(tree.child[file], repoConfig);
}
return output;
@@ -320,8 +320,8 @@ module.exports.isFilePathValid = async (options) => {
throw "file_not_supported";
}
let unanonymizePath = options.path;
if (unanonymizePath.indexOf("XXX") > -1) {
let anonymizePath = options.path;
if (anonymizePath.indexOf("XXX") > -1) {
const files = await module.exports.getFileList({ repoConfig });
const file = getFile(files, options.path);
@@ -335,23 +335,23 @@ module.exports.isFilePathValid = async (options) => {
const shatree = tree2sha(r.originalFiles);
if (shatree[file.sha]) {
unanonymizePath = shatree[file.sha];
anonymizePath = shatree[file.sha];
}
}
}
const orignalFilePath = path.join(
const originalFilePath = path.join(
repoUtils.getOriginalPath(repoConfig.repoId),
unanonymizePath
anonymizePath
);
if (ofs.existsSync(anonymizedFilePath)) {
return true;
}
if (ofs.existsSync(orignalFilePath)) {
if (ofs.existsSync(originalFilePath)) {
if (!module.exports.isFileSupported(repoConfig, anonymizedFilePath)) {
throw "file_not_supported";
}
await anonymizeUtils.ananymiseFile(
orignalFilePath,
await anonymizeUtils.anonymizeFile(
originalFilePath,
anonymizedFilePath,
repoConfig
);
@@ -432,14 +432,14 @@ module.exports.isFilePathValid = async (options) => {
}
try {
await fs.mkdir(path.dirname(orignalFilePath), { recursive: true });
await fs.mkdir(path.dirname(originalFilePath), { recursive: true });
} catch (_) {
// ignore
}
try {
await fs.writeFile(orignalFilePath, content, { encoding: "utf-8" });
await anonymizeUtils.ananymiseFile(
orignalFilePath,
await fs.writeFile(originalFilePath, content, { encoding: "utf-8" });
await anonymizeUtils.anonymiseFile(
originalFilePath,
anonymizedFilePath,
repoConfig
);

View File

@@ -32,7 +32,7 @@ module.exports.downloadRepoAndAnonymize = async (repoConfig) => {
return true;
}
if (repoConfig.options.mode == "download") {
// if cache folder does not exist download and anonumize it
// if cache folder does not exist download and anonymize it
const originalPath = repoUtils.getOriginalPath(repoConfig.repoId);

View File

@@ -308,7 +308,7 @@ module.exports.getRepoReadme = async (options) => {
}
};
module.exports.updateAnonimizedRepository = async (repoConfig) => {
module.exports.updateAnonymizedRepository = async (repoConfig) => {
if (repoConfig.status == "updating") {
throw "repo_is_updating";
}