[EXPERIMENTAL] linux apps support
This commit is contained in:
parent
d4996988d9
commit
e7636afe3d
20 changed files with 1377 additions and 101 deletions
|
|
@ -161,6 +161,44 @@ async function copyTree(src, dst, onProgress) {
|
|||
return { done, bytes }
|
||||
}
|
||||
|
||||
// Imported trees come from media that lose permissions (archives, FAT, a
|
||||
// read-only backup drive), and copyFile keeps whatever the source had: every
|
||||
// node gets owner rwx and `x` mirrored from `r`, so the app can run its own
|
||||
// binaries and write its own files.
|
||||
async function chmodTree(root) {
|
||||
const desired = mode => mode | 0o700 | ((mode & 0o444) >> 2)
|
||||
let files = 0
|
||||
let dirs = 0
|
||||
const walk = async dir => {
|
||||
let entries
|
||||
try {
|
||||
entries = await fsp.readdir(dir, { withFileTypes: true })
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
for (const entry of entries) {
|
||||
const full = path.join(dir, entry.name)
|
||||
if (entry.isSymbolicLink()) continue
|
||||
if (entry.isDirectory()) {
|
||||
await walk(full)
|
||||
} else if (!entry.isFile()) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
const before = (await fsp.stat(full)).mode & 0o7777
|
||||
const after = desired(before)
|
||||
if (after !== before) {
|
||||
await fsp.chmod(full, after)
|
||||
if (entry.isDirectory()) dirs++
|
||||
else files++
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
await walk(root)
|
||||
return { files, dirs }
|
||||
}
|
||||
|
||||
// Delete deepest-first with progress through onProgress; symlinks are
|
||||
// unlinked, never followed.
|
||||
async function removeTree(root, onProgress) {
|
||||
|
|
@ -228,5 +266,5 @@ async function removeTree(root, onProgress) {
|
|||
return { files, dirs, bytes }
|
||||
}
|
||||
|
||||
module.exports = { pathExists, dedupeDir, copyTree, treeSize, removeTree, progressGate, mapLimit }
|
||||
module.exports = { pathExists, dedupeDir, copyTree, treeSize, removeTree, chmodTree, progressGate, mapLimit }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue