Skip to content

Commit 65d04c4

Browse files
committed
dev(puterfs): move misc methods to extension
The get_capabilities and update_thumbnail methods in PuterFSProvider are moved to the extension by this commit. This is prerequisite to the removal of PuterFSProvider in the core.
1 parent 3ef52fd commit 65d04c4

File tree

2 files changed

+59
-48
lines changed

2 files changed

+59
-48
lines changed

extensions/puterfs/main.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const {
7979

8080
const {
8181
FSNodeContext,
82+
capabilities,
8283
} = extension.import('fs');
8384

8485
const {
@@ -99,6 +100,25 @@ const {
99100
} = extension.import('fs').util;
100101

101102
class PuterFSProvider {
103+
// TODO: should this be a static member instead?
104+
get_capabilities () {
105+
return new Set([
106+
capabilities.THUMBNAIL,
107+
capabilities.UPDATE_THUMBNAIL,
108+
capabilities.UUID,
109+
capabilities.OPERATION_TRACE,
110+
capabilities.READDIR_UUID_MODE,
111+
112+
capabilities.COPY_TREE,
113+
114+
capabilities.READ,
115+
capabilities.WRITE,
116+
capabilities.CASE_SENSITIVE,
117+
capabilities.SYMLINK,
118+
capabilities.TRASH,
119+
]);
120+
}
121+
102122
/**
103123
* Check if a given node exists.
104124
*
@@ -226,6 +246,41 @@ class PuterFSProvider {
226246
return node;
227247
}
228248

249+
async update_thumbnail ({ context, node, thumbnail }) {
250+
const {
251+
actor: inputActor,
252+
} = context.values;
253+
const actor = inputActor ?? Context.get('actor');
254+
255+
context = context ?? Context.get();
256+
const services = context.get('services');
257+
258+
// TODO: this ACL check should not be here, but there's no LL method yet
259+
// and it's possible we will never implement the thumbnail
260+
// capability for any other filesystem type
261+
262+
const svc_acl = services.get('acl');
263+
if ( ! await svc_acl.check(actor, node, 'write') ) {
264+
throw await svc_acl.get_safe_acl_error(actor, node, 'write');
265+
}
266+
267+
const uid = await node.get('uid');
268+
269+
const entryOp = await svc_fsEntry.update(uid, {
270+
thumbnail,
271+
});
272+
273+
(async () => {
274+
await entryOp.awaitDone();
275+
svc_event.emit('fs.write.file', {
276+
node,
277+
context,
278+
});
279+
})();
280+
281+
return node;
282+
}
283+
229284
async read ({ context, node, version_id, range }) {
230285
const svc_mountpoint = context.get('services').get('mountpoint');
231286
const storage = svc_mountpoint.get_storage(this.constructor.name);

src/backend/src/modules/puterfs/lib/PuterFSProvider.js

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919

2020
const putility = require('@heyputer/putility');
21-
const { Context } = require('../../../util/context');
22-
const fsCapabilities = require('../../../filesystem/definitions/capabilities');
2321
const config = require('../../../config.js');
2422

2523
class PuterFSProvider extends putility.AdvancedBase {
@@ -31,21 +29,8 @@ class PuterFSProvider extends putility.AdvancedBase {
3129
}
3230

3331
get_capabilities () {
34-
return new Set([
35-
fsCapabilities.THUMBNAIL,
36-
fsCapabilities.UPDATE_THUMBNAIL,
37-
fsCapabilities.UUID,
38-
fsCapabilities.OPERATION_TRACE,
39-
fsCapabilities.READDIR_UUID_MODE,
40-
41-
fsCapabilities.COPY_TREE,
42-
43-
fsCapabilities.READ,
44-
fsCapabilities.WRITE,
45-
fsCapabilities.CASE_SENSITIVE,
46-
fsCapabilities.SYMLINK,
47-
fsCapabilities.TRASH,
48-
]);
32+
console.error('This .get_capabilities should not be called!');
33+
throw new Error('This .get_capabilities should not be called!');
4934
}
5035

5136
/**
@@ -106,37 +91,8 @@ class PuterFSProvider extends putility.AdvancedBase {
10691
}
10792

10893
async update_thumbnail ({ context, node, thumbnail }) {
109-
const {
110-
actor: inputActor,
111-
} = context.values;
112-
const actor = inputActor ?? Context.get('actor');
113-
114-
context = context ?? Context.get();
115-
const services = context.get('services');
116-
117-
const svc_fsEntry = services.get('fsEntryService');
118-
const svc_event = services.get('event');
119-
120-
const svc_acl = services.get('acl');
121-
if ( ! await svc_acl.check(actor, node, 'write') ) {
122-
throw await svc_acl.get_safe_acl_error(actor, node, 'write');
123-
}
124-
125-
const uid = await node.get('uid');
126-
127-
const entryOp = await svc_fsEntry.update(uid, {
128-
thumbnail,
129-
});
130-
131-
(async () => {
132-
await entryOp.awaitDone();
133-
svc_event.emit('fs.write.file', {
134-
node,
135-
context,
136-
});
137-
})();
138-
139-
return node;
94+
console.error('This .update_thumbnail should not be called!');
95+
throw new Error('This .update_thumbnail should not be called!');
14096
}
14197

14298
/**

0 commit comments

Comments
 (0)