refactor(backend): remove PuterFSProvider from core

This commit is contained in:
KernelDeimos
2025-11-11 14:35:22 -05:00
committed by Eric Dubé
parent 8d4f788888
commit ba994f8d88
8 changed files with 34 additions and 265 deletions

View File

@@ -918,12 +918,10 @@ class PuterFSProvider {
}
}
const { TmpProxyFSProvider } = extension.import('fs');
extension.on('create.filesystem-types', event => {
event.createFilesystemType('puterfs', {
mount ({ path }) {
return new TmpProxyFSProvider(path, new PuterFSProvider(path));
return new PuterFSProvider(path);
},
});
});

View File

@@ -28,7 +28,6 @@ const { UserActorType } = require('../services/auth/Actor');
const { get_user } = require('../helpers');
const BaseService = require('../services/BaseService');
const { MANAGE_PERM_PREFIX } = require('../services/auth/permissionConts.mjs');
const { PuterFSProvider } = require('../modules/puterfs/lib/PuterFSProvider.js');
const { quot } = require('@heyputer/putility/src/libs/string.js');
class FilesystemService extends BaseService {
@@ -95,7 +94,7 @@ class FilesystemService extends BaseService {
|| permission.startsWith(`${MANAGE_PERM_PREFIX}:${MANAGE_PERM_PREFIX}:fs:`); // owner has implicit rule to give others manage access;
},
checker: async ({ actor, permission }) => {
if ( !(actor.type instanceof UserActorType) ) {
if ( ! (actor.type instanceof UserActorType) ) {
return undefined;
}
@@ -109,7 +108,7 @@ class FilesystemService extends BaseService {
const owner_id = await node.get('user_id');
// These conditions should never happen
if ( ! owner_id || ! actor.type.user.id ) {
if ( !owner_id || !actor.type.user.id ) {
throw new Error('something unexpected happened');
}
@@ -330,8 +329,8 @@ class FilesystemService extends BaseService {
}
if ( ! (selector instanceof NodeSelector) ) {
throw new Error('FileSystemService could not resolve the specified node value ' +
quot('' + selector) + ` (type: ${typeof selector}) ` +
throw new Error(`FileSystemService could not resolve the specified node value ${
quot(`${ selector}`) } (type: ${typeof selector}) ` +
'to a filesystem node selector');
}

View File

@@ -22,7 +22,6 @@ const FSNodeContext = require('../../filesystem/FSNodeContext');
const capabilities = require('../../filesystem/definitions/capabilities');
const selectors = require('../../filesystem/node/selectors');
const { RuntimeModule } = require('../../extension/RuntimeModule');
const { TmpProxyFSProvider } = require('./TmpProxyFSProvider');
const { MODE_READ, MODE_WRITE } = require('../../services/fs/FSLockService');
const { UploadProgressTracker } = require('../../filesystem/storage/UploadProgressTracker');
@@ -39,7 +38,6 @@ class PuterFSModule extends AdvancedBase {
capabilities,
selectors,
FSNodeContext,
TmpProxyFSProvider,
lock: {
MODE_READ,
MODE_WRITE,

View File

@@ -1,41 +0,0 @@
/*
* Copyright (C) 2024-present Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const BaseService = require("../../services/BaseService");
const { PuterFSProvider } = require("./lib/PuterFSProvider");
class PuterFSService extends BaseService {
async _init () {
const svc_mountpoint = this.services.get('mountpoint');
svc_mountpoint.register_mounter('puterfs', this.as('mounter'));
}
static IMPLEMENTS = {
mounter: {
async mount ({ path, options }) {
const provider = new PuterFSProvider();
return provider;
}
}
}
}
module.exports = {
PuterFSService,
};

View File

@@ -1,40 +0,0 @@
const { PuterFSProvider } = require("./lib/PuterFSProvider");
/**
* This is a temporary filesystem provider implementation that will
* proxy calls to either the new PuterFS implementation from the
* `puterfs` extension (if the method is implemented), or to the
* soon-to-be-legacy implementation in Puter's core otherwise.
*
* Once all of the methods for PuterFS have been moved to the
* extension, this temporary proxy provider FS Provider will be
* removed.
*/
class TmpProxyFSProvider {
constructor (path, puterfs) {
this.puterfs = puterfs;
this.legacyfs = new PuterFSProvider();
return new Proxy(this, {
get (target, prop, _receiver) {
if ( prop in target.puterfs ) {
const value = target.puterfs[prop];
if ( typeof value === 'function' ) {
return value.bind(target.puterfs);
}
return value;
}
const value = target.legacyfs[prop];
if ( typeof value === 'function' ) {
return value.bind(target.legacyfs);
}
return value;
},
})
}
}
module.exports = {
TmpProxyFSProvider,
};

View File

@@ -1,137 +0,0 @@
/*
* Copyright (C) 2024-present Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const putility = require('@heyputer/putility');
const config = require('../../../config.js');
class PuterFSProvider extends putility.AdvancedBase {
constructor (...a) {
super(...a);
this.log_fsentriesNotFound = (config.logging ?? [])
.includes('fsentries-not-found');
}
get_capabilities () {
console.error('This .get_capabilities should not be called!');
throw new Error('This .get_capabilities should not be called!');
}
/**
* Check if a given node exists.
*
* @param {Object} param
* @param {NodeSelector} param.selector - The selector used for checking.
* @returns {Promise<boolean>} - True if the node exists, false otherwise.
*/
async quick_check () {
console.error('This .quick_check should not be called!');
throw new Error('This .quick_check should not be called!');
}
async stat () {
console.error('This .stat should not be called!');
throw new Error('This .stat should not be called!');
}
async readdir () {
console.error('This .readdir should not be called!');
throw new Error('This .readdir should not be called!');
}
async move () {
console.error('This .move should not be called!');
throw new Error('This .move should not be called!');
}
async copy_tree () {
console.error('This .copy_tree should not be called!');
throw new Error('This .copy_tree should not be called!');
}
async unlink () {
console.error('This .unlink should not be called!');
throw new Error('This .unlink should not be called!');
}
async rmdir () {
console.error('This .rmdir should not be called!');
throw new Error('This .rmdir should not be called!');
}
/**
* Create a new directory.
*
* @param {Object} param
* @param {Context} param.context
* @param {FSNode} param.parent
* @param {string} param.name
* @param {boolean} param.immutable
* @returns {Promise<FSNode>}
*/
async mkdir () {
console.error('This .mkdir should not be called!');
throw new Error('This .mkdir should not be called!');
}
async update_thumbnail ({ context, node, thumbnail }) {
console.error('This .update_thumbnail should not be called!');
throw new Error('This .update_thumbnail should not be called!');
}
/**
* Write a new file to the filesystem. Throws an error if the destination
* already exists.
*
* @param {Object} param
* @param {Context} param.context
* @param {FSNode} param.parent: The parent directory of the file.
* @param {string} param.name: The name of the file.
* @param {File} param.file: The file to write.
* @returns {Promise<FSNode>}
*/
async write_new () {
console.error('This .write_new should not be called!');
throw new Error('This .write_new should not be called!');
}
/**
* Overwrite an existing file. Throws an error if the destination does not
* exist.
*
* @param {Object} param
* @param {Context} param.context
* @param {FSNodeContext} param.node: The node to write to.
* @param {File} param.file: The file to write.
* @returns {Promise<FSNodeContext>}
*/
async write_overwrite () {
console.error('This .write_overwrite should not be called!');
throw new Error('This .write_overwrite should not be called!');
}
async read () {
console.error('This .read should not be called!');
throw new Error('This .read should not be called!');
}
}
module.exports = {
PuterFSProvider,
};

View File

@@ -1,10 +1,9 @@
const APIError = require("../../api/APIError");
const eggspress = require("../../api/eggspress");
const FSNodeParam = require("../../api/filesystem/FSNodeParam");
const StringParam = require("../../api/filesystem/StringParam");
const { is_valid_url } = require("../../helpers");
const { PuterFSProvider } = require("../../modules/puterfs/lib/PuterFSProvider");
const { Context } = require("../../util/context");
const APIError = require('../../api/APIError');
const eggspress = require('../../api/eggspress');
const FSNodeParam = require('../../api/filesystem/FSNodeParam');
const StringParam = require('../../api/filesystem/StringParam');
const { is_valid_url } = require('../../helpers');
const { Context } = require('../../util/context');
module.exports = eggspress('/update-fsentry-thumbnail', {
subdomain: 'api',
@@ -25,22 +24,22 @@ module.exports = eggspress('/update-fsentry-thumbnail', {
got: typeof req.values.thumbnail,
});
}
if ( ! await req.values.fsNode.exists() ) {
throw new APIError.create('subject_does_not_exist');
}
const svc = Context.get('services');
const svc_mountpoint = svc.get('mountpoint');
const provider =
await svc_mountpoint.get_provider(req.values.fsNode.selector);
provider.update_thumbnail({
context: Context.get(),
node: req.values.fsNode,
thumbnail: req.body.thumbnail,
});
res.json({});
});

View File

@@ -17,12 +17,10 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const { LocalDiskStorageStrategy } = require("../filesystem/strategies/storage_a/LocalDiskStorageStrategy");
const { PuterFSProvider } = require("../modules/puterfs/lib/PuterFSProvider");
const { LocalDiskStorageStrategy } = require('../filesystem/strategies/storage_a/LocalDiskStorageStrategy');
const { TeePromise } = require('@heyputer/putility').libs.promise;
const { progress_stream, size_limit_stream } = require("../util/streamutil");
const BaseService = require("./BaseService");
const { progress_stream, size_limit_stream } = require('../util/streamutil');
const BaseService = require('./BaseService');
/**
* @class LocalDiskStorageService
@@ -36,8 +34,7 @@ class LocalDiskStorageService extends BaseService {
static MODULES = {
fs: require('fs'),
path: require('path'),
}
};
/**
* Initializes the context for the storage service.
@@ -51,11 +48,12 @@ class LocalDiskStorageService extends BaseService {
const svc_contextInit = this.services.get('context-init');
const storage = new LocalDiskStorageStrategy({ services: this.services });
svc_contextInit.register_value('storage', storage);
const svc_mountpoint = this.services.get('mountpoint');
svc_mountpoint.set_storage(PuterFSProvider.name, storage);
}
// TODO: this is rather silly and can be removed once the storage
// implementation is moved into the extension as part of puterfs
const svc_mountpoint = this.services.get('mountpoint');
svc_mountpoint.set_storage('PuterFSProvider', storage);
}
/**
* Initializes the local disk storage service.
@@ -81,7 +79,6 @@ class LocalDiskStorageService extends BaseService {
return path.join(this.path, key);
}
/**
* Stores a stream to local disk storage.
*
@@ -105,7 +102,7 @@ class LocalDiskStorageService extends BaseService {
total: size,
progress_callback: on_progress,
});
stream = size_limit_stream(stream, {
limit: size,
});
@@ -122,7 +119,6 @@ class LocalDiskStorageService extends BaseService {
return await writePromise;
}
/**
* Stores a buffer to the local disk.
*
@@ -141,7 +137,6 @@ class LocalDiskStorageService extends BaseService {
await fs.promises.writeFile(path, buffer);
}
/**
* Creates a read stream for a given key.
*
@@ -155,31 +150,30 @@ class LocalDiskStorageService extends BaseService {
const fs = require('fs');
const path = this._get_path(uid);
// Handle range requests for partial content
const { range } = options;
if (range) {
if ( range ) {
const rangeMatch = range.match(/bytes=(\d+)-(\d*)/);
if (rangeMatch) {
if ( rangeMatch ) {
const start = parseInt(rangeMatch[1], 10);
const endStr = rangeMatch[2];
const streamOptions = { start };
// If end is specified, set it (fs.createReadStream end is inclusive)
if (endStr) {
if ( endStr ) {
streamOptions.end = parseInt(endStr, 10);
}
return fs.createReadStream(path, streamOptions);
}
}
// Default: create stream for entire file
return fs.createReadStream(path);
}
/**
* Copies a file from one key to another within the local disk storage.
*
@@ -198,7 +192,6 @@ class LocalDiskStorageService extends BaseService {
await fs.promises.copyFile(src_path, dst_path);
}
/**
* Deletes a file from the local disk storage.
*