Merge pull request #241 from vineeth-vk11/#233

Implementing HostDiskUsageService removing diskusage dependency
This commit is contained in:
Eric Dubé
2024-04-06 05:29:21 -04:00
committed by GitHub
5 changed files with 73 additions and 27 deletions

19
package-lock.json generated
View File

@@ -12,7 +12,6 @@
"packages/*"
],
"dependencies": {
"diskusage": "^1.2.0",
"uuid": "^9.0.1"
},
"devDependencies": {
@@ -5245,16 +5244,6 @@
"md5": "^2.3.0"
}
},
"node_modules/diskusage": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/diskusage/-/diskusage-1.2.0.tgz",
"integrity": "sha512-2u3OG3xuf5MFyzc4MctNRUKjjwK+UkovRYdD2ed/NZNZPrt0lqHnLKxGhlFVvAb4/oufIgQG3nWgwmeTbHOvXA==",
"hasInstallScript": true,
"dependencies": {
"es6-promise": "^4.2.8",
"nan": "^2.18.0"
}
},
"node_modules/dom-serializer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
@@ -5492,11 +5481,6 @@
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
"dev": true
},
"node_modules/es6-promise": {
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz",
"integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w=="
},
"node_modules/escalade": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz",
@@ -7905,7 +7889,8 @@
"node_modules/nan": {
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.19.0.tgz",
"integrity": "sha512-nO1xXxfh/RWNxfd/XPfbIfFk5vgLsAxUR9y5O0cHMJu/AW9U95JLXqthYHjEp+8gQ5p96K9jUp8nbVOxCdRbtw=="
"integrity": "sha512-nO1xXxfh/RWNxfd/XPfbIfFk5vgLsAxUR9y5O0cHMJu/AW9U95JLXqthYHjEp+8gQ5p96K9jUp8nbVOxCdRbtw==",
"optional": true
},
"node_modules/napi-build-utils": {
"version": "1.0.2",

View File

@@ -39,7 +39,6 @@
]
},
"dependencies": {
"diskusage": "^1.2.0",
"uuid": "^9.0.1"
}
}

View File

@@ -23,6 +23,9 @@ class LocalDiskStorageModule extends AdvancedBase {
const services = context.get('services');
const LocalDiskStorageService = require("./services/LocalDiskStorageService");
services.registerService('local-disk-storage', LocalDiskStorageService);
const HostDiskUsageService = require('./services/HostDiskUsageService');
services.registerService('host-disk-usage', HostDiskUsageService);
}
}

View File

@@ -19,7 +19,6 @@
"use strict"
const deep_proto_merge = require('./config/deep_proto_merge');
// const reserved_words = require('./config/reserved_words');
const diskusage = require('diskusage');
let config = {};
@@ -55,15 +54,9 @@ config.storage_capacity = 1*1024*1024*1024;
config.static_hosting_domain = '-static.puter.local';
// Storage limiting is set to false by default
// Storage available on the device puter is running is the storage available
// Storage available on the mountpoint/drive puter is running is the storage available
config.is_storage_limited = false;
diskusage.check('/', (err, info) => {
if (err) {
config.available_device_storage = 1*1024*1024*1024;
} else{
config.available_device_storage = info.free;
}
});
config.available_device_storage = null;
config.thumb_width = 80;
config.thumb_height = 80;

View File

@@ -0,0 +1,66 @@
const { BaseService } = require("../../exports");
const { execSync } = require('child_process');
const config = require("../config");
class HostDiskUsageService extends BaseService {
static DESCRIPTION = `
This service is responsible for identifying the mountpoint/drive
on which the current process working directory is running, and then checking the
disk usage of that mountpoint/drive.
`;
async _init() {
const current_platform = process.platform;
// Setting the available space to a large number for unhandled platforms
var free_space = 1e+14;
if (current_platform == "darwin") {
const mountpoint = this.get_darwin_mountpoint(process.cwd());
free_space = this.get_disk_capacity_darwin(mountpoint);
} else if (current_platform == "linux") {
this.log.warn('HostDiskUsageService: Linux is not supported yet');
// TODO: Implement for linux systems
} else if (current_platform == "win32") {
this.log.warn('HostDiskUsageService: Windows is not supported yet');
// TODO: Implement for windows systems
}
console.log('free_space:', free_space);
config.available_device_storage = free_space;
}
// Get the mountpoint/drive of the current working directory in mac os
get_darwin_mountpoint(directory) {
return execSync(`df -P "${directory}" | awk 'NR==2 {print $6}'`, { encoding: 'utf-8' }).trim();
}
// Get the mountpoint/drive of the current working directory in linux
get_linux_mountpint(directory) {
// TODO: Implement for linux systems
}
// Get the drive of the current working directory in windows
get_windows_drive(directory) {
// TODO: Implement for windows systems
}
// Get the free space on the mountpoint/drive in mac os
get_disk_capacity_darwin(mountpoint) {
const disk_info = execSync(`df -P "${mountpoint}" | awk 'NR==2 {print $4}'`, { encoding: 'utf-8' }).trim().split(' ');
return parseInt(disk_info) * 512;
}
// Get the free space on the mountpoint/drive in linux
get_disk_capacity_linux(mountpoint) {
// TODO: Implement for linux systems
}
// Get the free space on the drive in windows
get_disk_capacity_windows(drive) {
// TODO: Implement for windows systems
}
}
module.exports = HostDiskUsageService;