Skip to content

Commit 038eed9

Browse files
committed
fs: tidy code
1 parent cd93021 commit 038eed9

File tree

14 files changed

+26
-202
lines changed

14 files changed

+26
-202
lines changed

src/backend/src/filesystem/FSNodeContext.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ module.exports = class FSNodeContext {
121121
return result;
122122
}
123123
}
124-
125-
if ( (! this.path) && (! this.uid) ) {
126-
console.log('no path or uid');
127-
selector.setPropertiesKnownBySelector(this);
128-
console.log('no path or uid');
129-
}
130124
}
131125

132126
set selector (new_selector) {
@@ -294,24 +288,10 @@ module.exports = class FSNodeContext {
294288
controls,
295289
});
296290

297-
if ( entry === undefined ) {
298-
console.error('entry is undefined');
299-
this.found = false;
300-
this.entry = false;
301-
let entry_1 = await this.provider.stat({
302-
selector: this.selector,
303-
options: fetch_entry_options,
304-
node: this,
305-
controls,
306-
});
307-
return;
308-
}
309-
310-
if ( entry === null ) {
291+
if ( ! entry ) {
311292
this.found = false;
312293
this.entry = false;
313294
} else {
314-
315295
this.found = true;
316296

317297
if ( ! this.uid && entry.uuid ) {
@@ -383,9 +363,6 @@ module.exports = class FSNodeContext {
383363
async fetchOwner (force) {
384364
if ( this.isRoot ) return;
385365
const owner = await get_user({ id: this.entry.user_id });
386-
if ( ! owner ) {
387-
console.error('owner is undefined', this.entry);
388-
}
389366
this.entry.owner = {
390367
username: owner.username,
391368
email: owner.email,
@@ -755,17 +732,9 @@ module.exports = class FSNodeContext {
755732
}
756733
await this.fetchEntry(fetch_options);
757734

758-
if ( this.entry.id === 123 ) {
759-
console.log('this.entry', this.entry);
760-
}
761-
762735
const res = this.entry;
763736
const fsentry = {};
764737

765-
if ( this.entry === false ) {
766-
console.log('this.entry is false', this.entry);
767-
}
768-
769738
// This property will not be serialized, but it can be checked
770739
// by other code to verify that API calls do not send
771740
// unsanitized filsystem entries.
@@ -778,10 +747,6 @@ module.exports = class FSNodeContext {
778747
fsentry[k] = res[k];
779748
}
780749

781-
if ( this.entry === false ) {
782-
console.log('this.entry is false', this.entry);
783-
}
784-
785750
let actor; try {
786751
actor = Context.get('actor');
787752
} catch (e) {}

src/backend/src/filesystem/hl_operations/hl_copy.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,10 @@ class HLCopy extends HLFilesystemOperation {
159159
throw APIError.create('source_and_dest_are_the_same');
160160
}
161161

162-
if ( ! source.mysql_id ) {
163-
console.log('source.mysql_id', source.mysql_id);
164-
console.log('parent.mysql_id', parent.mysql_id);
165-
}
166-
167162
if ( await is_ancestor_of(source.uid, parent.uid) ) {
168163
throw APIError.create('cannot_copy_item_into_itself');
169164
}
170165

171-
// if ( await is_ancestor_of(source.mysql_id, parent.mysql_id) ) {
172-
// throw APIError('cannot_copy_item_into_itself');
173-
// }
174-
175166
let overwritten;
176167
if ( await dest.exists() ) {
177168
// condition: no overwrite behaviour specified

src/backend/src/filesystem/hl_operations/hl_mkdir.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const { HLFilesystemOperation } = require('./definitions');
3131
const { is_valid_path } = require('../validation');
3232
const { HLRemove } = require('./hl_remove');
3333
const { LLMkdir } = require('../ll_operations/ll_mkdir');
34-
const { MemoryFSService } = require('../../modules/puterfs/customfs/MemoryFSService');
3534

3635
class MkTree extends HLFilesystemOperation {
3736
static DESCRIPTION = `
@@ -300,10 +299,6 @@ class HLMkdir extends HLFilesystemOperation {
300299
});
301300
}
302301

303-
if ( values.dedupe_name ) {
304-
console.log('DEDUPE NAME', values.dedupe_name);
305-
}
306-
307302
// `parent_node` becomes the parent of the last directory name
308303
// specified under `path`.
309304
parent_node = await this._create_parents({
@@ -322,10 +317,6 @@ class HLMkdir extends HLFilesystemOperation {
322317

323318
await existing.fetchEntry();
324319

325-
if ( values.dedupe_name ) {
326-
console.log('DEDUPE NAME', values.dedupe_name);
327-
}
328-
329320
if ( existing.found ) {
330321
const { overwrite, dedupe_name, create_missing_parents } = values;
331322
if ( overwrite ) {
@@ -340,10 +331,6 @@ class HLMkdir extends HLFilesystemOperation {
340331
});
341332
}
342333
else if ( dedupe_name ) {
343-
if ( parent_node.provider instanceof MemoryFSService ) {
344-
console.log('MEMORYFS DEDUPE');
345-
}
346-
347334
const fs = context.get('services').get('filesystem');
348335
const parent_selector = parent_node.selector;
349336
for ( let i=1 ;; i++ ) {
@@ -508,17 +495,9 @@ class HLMkdir extends HLFilesystemOperation {
508495

509496
const fs = this.context.get('services').get('filesystem');
510497

511-
let parent = await fs.node(new RootNodeSelector());
512-
// if ( mountpoint && mountpoint !== '/' ) {
513-
// parent = await fs.node(new NodePathSelector(mountpoint));
514-
515-
// // remove the mountpoint from the path
516-
// path = path.replace(mountpoint, '');
517-
// }
518-
519498
const tree_op = new MkTree();
520499
await tree_op.run({
521-
parent: parent,
500+
parent: await fs.node(new RootNodeSelector()),
522501
tree: [path],
523502
});
524503

src/backend/src/filesystem/hl_operations/hl_move.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ class HLMove extends HLFilesystemOperation {
182182
const old_path = await source.get('path');
183183

184184
const ll_move = new LLMove();
185-
186-
console.log(`source: ${JSON.stringify(source.entry)}`);
187-
188185
const source_new = await ll_move.run({
189186
source,
190187
parent,
@@ -193,8 +190,6 @@ class HLMove extends HLFilesystemOperation {
193190
metadata: metadata,
194191
});
195192

196-
console.log(`source_new: ${JSON.stringify(source_new.entry)}`);
197-
198193
await source_new.awaitStableEntry();
199194
await source_new.fetchSuggestedApps();
200195
await source_new.fetchOwner();

src/backend/src/filesystem/hl_operations/hl_read.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ class HLRead extends HLFilesystemOperation {
3434
version_id,
3535
} = this.values;
3636

37-
if ( fsNode.path.includes('tmp') ) {
38-
console.log('tmp');
39-
}
40-
4137
if ( ! await fsNode.exists() ) {
4238
throw APIError.create('subject_does_not_exist');
4339
}

src/backend/src/filesystem/ll_operations/ll_read.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ class LLRead extends LLFilesystemOperation {
7171
async function calculate_has_range (a) {
7272
const { offset, length } = a.values();
7373
const fsNode = a.get('fsNode');
74-
if ( fsNode.entry.id === 123 ) {
75-
console.log('has_range', offset, length);
76-
}
7774
const has_range = (
7875
offset !== undefined &&
7976
offset !== 0
@@ -153,6 +150,7 @@ class LLRead extends LLFilesystemOperation {
153150
const { fsNode, stream, has_range } = a.values();
154151

155152
if ( ! has_range ) {
153+
// only cache for non-memoryfs providers
156154
if ( ! (fsNode.provider instanceof MemoryFSProvider) ) {
157155
const res = await svc_fileCache.maybe_store(fsNode, stream);
158156
if ( res.stream ) a.set('stream', res.stream);

src/backend/src/filesystem/node/selectors.js

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -96,45 +96,13 @@ class NodeChildSelector extends NodeSelector {
9696
this.name = name;
9797
}
9898

99-
/**
100-
* Try to infer the absolute path of the node.
101-
*
102-
* @returns {string|null} the absolute path of the node, or null if the path cannot be inferred
103-
*/
104-
try_infer_path () {
105-
// try to get the full path recursively
106-
//
107-
// TODO (xiaochen): this is a hack to get the absolute path and should be removed once
108-
// we have a better solution. We need the absolute path so that `MountpointService`
109-
// can determine the mountpoint and provider for the node.
110-
const stack = [this.name];
111-
let current = this.parent;
112-
while ( current ) {
113-
if ( current instanceof NodeChildSelector ) {
114-
stack.push(current.name);
115-
current = current.parent;
116-
} else if ( current instanceof NodePathSelector ) {
117-
stack.push(current.value);
118-
current = null;
119-
} else if ( current instanceof RootNodeSelector ) {
120-
current = null;
121-
} else {
122-
// for other selectors, we can't determine the absolute path
123-
return null;
124-
}
125-
}
126-
127-
let path = '/';
128-
stack.reverse().forEach(item => {
129-
path = _path.join(path, item);
130-
});
131-
132-
return path;
133-
}
134-
13599
setPropertiesKnownBySelector (node) {
136100
node.name = this.name;
137-
node.path = this.try_infer_path();
101+
102+
try_infer_attributes(this);
103+
if ( this.path ) {
104+
node.path = this.path;
105+
}
138106
}
139107

140108
describe () {
@@ -212,7 +180,7 @@ function try_infer_attributes (selector) {
212180
} else if ( selector instanceof RootNodeSelector ) {
213181
selector.path = '/';
214182
} else {
215-
throw new Error('invalid selector');
183+
// give up
216184
}
217185
}
218186

src/backend/src/helpers.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ async function is_user_signup_disabled() {
9797
}
9898

9999
const chkperm = spanify('chkperm', async (target_fsentry, requester_user_id, action) => {
100-
// TODO (xiaochen): remove this branch after the related ACL permission logic is implemented for "MemoryFSProvider".
101-
if (target_fsentry.is_public) {
102-
console.log('TRUE BECAUSE IS_PUBLIC')
103-
// return true;
104-
}
105-
106100
// basic cases where false is the default response
107101
if(!target_fsentry)
108102
return false;
@@ -978,7 +972,7 @@ const body_parser_error_handler = (err, req, res, next) => {
978972
* TODO (xiaochen): It only works for MemoryFSProvider currently.
979973
*
980974
* @param {string} uid - The uid of the file to get.
981-
* @returns {Promise<FileInfo|null>} The file node, or null if the file does not exist.
975+
* @returns {Promise<MemoryFile|null>} The file node, or null if the file does not exist.
982976
*/
983977
async function get_entry(uid) {
984978
const svc_mountpoint = Context.get('services').get('mountpoint');
@@ -996,14 +990,10 @@ async function get_entry(uid) {
996990
}
997991

998992
async function is_ancestor_of(ancestor_uid, descendant_uid){
999-
console.log('is_ancestor_of', ancestor_uid, descendant_uid);
1000-
1001993
const ancestor = await get_entry(ancestor_uid);
1002994
const descendant = await get_entry(descendant_uid);
1003995

1004996
if ( ancestor && descendant ) {
1005-
console.log('ancestor', ancestor);
1006-
console.log('descendant', descendant);
1007997
return descendant.path.startsWith(ancestor.path);
1008998
}
1009999

@@ -1028,11 +1018,6 @@ async function is_ancestor_of(ancestor_uid, descendant_uid){
10281018
let parent = await db.read("SELECT `uuid`, `parent_uid` FROM `fsentries` WHERE `uuid` = ? LIMIT 1", [descendant_uid]);
10291019
if(parent[0] === undefined)
10301020
parent = await db.pread("SELECT `uuid`, `parent_uid` FROM `fsentries` WHERE `uuid` = ? LIMIT 1", [descendant_uid]);
1031-
1032-
if ( ! parent[0]?.uuid ) {
1033-
console.log('parent[0].uuid is undefined', parent[0]);
1034-
}
1035-
10361021
if(parent[0].uuid === ancestor_uid || parent[0].parent_uid === ancestor_uid){
10371022
return true;
10381023
}

src/backend/src/modules/puterfs/MountpointService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
// const Mountpoint = o => ({ ...o });
2121

22-
const { RootNodeSelector, NodeUIDSelector, NodeChildSelector, NodePathSelector, NodeInternalIDSelector, NodeSelector } = require("../../filesystem/node/selectors");
22+
const { RootNodeSelector, NodeUIDSelector, NodeChildSelector, NodePathSelector, NodeInternalIDSelector, NodeSelector, try_infer_attributes } = require("../../filesystem/node/selectors");
2323
const BaseService = require("../../services/BaseService");
2424

2525
/**
@@ -112,9 +112,9 @@ class MountpointService extends BaseService {
112112
}
113113

114114
if ( selector instanceof NodeChildSelector ) {
115-
const path = selector.try_infer_path();
116-
if ( path ) {
117-
return this.get_provider(new NodePathSelector(path));
115+
try_infer_attributes(selector);
116+
if ( selector.path ) {
117+
return this.get_provider(new NodePathSelector(selector.path));
118118
} else {
119119
return this.get_provider(selector.parent);
120120
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,10 @@ class PuterFSProvider extends putility.AdvancedBase {
378378
}
379379

380380
async rmdir ({ context, node, options = {} }) {
381-
// // TODO (xiaochen): remove/refactor this branch, or this function, it's weird since
382-
// // `TYPE_DIRECTORY` is `undefined`
383-
// if ( TYPE_DIRECTORY ) {
384381
if ( await node.get('type') !== TYPE_DIRECTORY ) {
385382
console.log(`\x1B[31;1m===D1====${await node.get('path')}=========\x1B[0m`)
386383
throw new APIError(409, 'Cannot rmdir a file.');
387384
}
388-
// }
389385

390386
if ( await node.get('immutable') ) {
391387
console.log(`\x1B[31;1m===D2====${await node.get('path')}=========\x1B[0m`)

0 commit comments

Comments
 (0)