Мелкий рефакторинг
This commit is contained in:
@@ -57,23 +57,36 @@ class MegaStorage {
|
|||||||
await fs.writeFile(nameHash.descPath, JSON.stringify(desc, null, 2));
|
await fs.writeFile(nameHash.descPath, JSON.stringify(desc, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
async readFiles(callback, dir) {
|
async _findFiles(callback, dir) {
|
||||||
if (!callback)
|
if (!callback || !this.readingFiles)
|
||||||
return;
|
return;
|
||||||
if (!dir)
|
if (!dir)
|
||||||
dir = this.megaStorageDir;
|
dir = this.megaStorageDir;
|
||||||
|
|
||||||
const files = await fs.readdir(dir, { withFileTypes: true });
|
const files = await fs.readdir(dir, { withFileTypes: true });
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
if (!this.readingFiles)
|
||||||
|
return;
|
||||||
const found = path.resolve(dir, file.name);
|
const found = path.resolve(dir, file.name);
|
||||||
if (file.isDirectory())
|
if (file.isDirectory())
|
||||||
await this.readFiles(callback, found);
|
await this._findFiles(callback, found);
|
||||||
else
|
else
|
||||||
callback(found);
|
callback(found);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async stopReadFiles() {
|
async startFindFiles(callback, dir) {
|
||||||
|
this.readingFiles = true;
|
||||||
|
try {
|
||||||
|
return await this._findFiles(callback, dir);
|
||||||
|
} finally {
|
||||||
|
this.readingFiles = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async stopFindFiles() {
|
||||||
|
this.readingFiles = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getStats(gather = false) {
|
async getStats(gather = false) {
|
||||||
|
|||||||
Reference in New Issue
Block a user