file persistance fix

This commit is contained in:
Thomas Hobson 2021-04-28 16:03:35 +12:00
parent a6bc24e22e
commit 3bd73d07a9
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
3 changed files with 59 additions and 6 deletions

View File

@ -16,5 +16,11 @@ module.exports = {
},
version: require('../package.json').version,
platform,
pkg_installed_file: '.ppman-installed' //Used as indication for if a package was installed
pkg_installed_file: '.ppman-installed', //Used as indication for if a package was installed
clean_directories: [
"/dev/shm",
"/run/lock",
"/tmp",
"/var/tmp"
]
};

View File

@ -183,12 +183,10 @@ class Job {
};
}
async cleanup() {
logger.info(`Cleaning up job uuid=${this.uuid}`);
await fs.rm(this.dir, { recursive: true, force: true });
async cleanup_processes(){
let processes = [1];
while(processes.length > 0){
processes = await ps_list();
processes = processes.filter(proc => proc.uid == this.uid);
@ -212,8 +210,32 @@ class Job {
wait_pid(proc.pid);
}
}
}
async cleanup_filesystem(){
/*
for (const clean_path of globals.clean_directories) {
const contents = await fs.readdir(clean_path);
for (const file of contents) {
const file_path = path.join(clean_path, file);
const stat = await fs.stat(file_path);
if(stat.uid == this.uid)
await fs.rm(file_path, { recursive: true, force: true });
}
}*/
await fs.rm(this.dir, { recursive: true, force: true });
}
async cleanup() {
logger.info(`Cleaning up job uuid=${this.uuid}`);
await Promise.all([
this.cleanup_processes(),
this.cleanup_filesystem()
]);
}
}

25
tests/file_persistance.py Normal file
View File

@ -0,0 +1,25 @@
"""
Description
Files can be written into world writable directories without being removed,
potentially leading to disk space exhaustion
Run this test twice and there should be no output
"""
import os
directories = [
"/dev/shm",
"/run/lock",
"/tmp",
"/var/tmp"
]
for dir in directories:
fpath = f"{dir}/bean"
if os.path.exists(fpath):
print(f"{fpath} exists")
else:
with open(fpath, "w") as f:
f.write("beannn")