-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure crawler can't run out of space with --diskUtilization param #264
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import child_process from "child_process"; | ||
import fs from "fs"; | ||
import fsp from "fs/promises"; | ||
import util from "util"; | ||
|
||
import os from "os"; | ||
import { createHash } from "crypto"; | ||
|
@@ -148,6 +150,21 @@ export async function getDirSize(dir) { | |
return size; | ||
} | ||
|
||
export async function getDiskUsage(path="/") { | ||
const exec = util.promisify(child_process.exec); | ||
const result = await exec(`df ${path}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this is the best way to check disk usage... i guess maybe it is, instead of using some node library for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked for node libraries first (like https://www.npmjs.com/package/check-disk-space and https://www.npmjs.com/package/diskusage) but they all seemed to be wrappers for OS tools like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair enough! |
||
const lines = result.stdout.split("\n"); | ||
const keys = lines[0].split(/\s+/ig); | ||
const rows = lines.slice(1).map(line => { | ||
const values = line.split(/\s+/ig); | ||
return keys.reduce((o, k, index) => { | ||
o[k] = values[index]; | ||
return o; | ||
}, {}); | ||
}); | ||
return rows[0]; | ||
} | ||
|
||
function checksumFile(hashName, path) { | ||
return new Promise((resolve, reject) => { | ||
const hash = createHash(hashName); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, yes, this is a better way to do this!