Skip to content

Commit 7f1b870

Browse files
committed
feat: support readdir for directory symlinks
1 parent c2a9506 commit 7f1b870

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/backend/src/filesystem/hl_operations/hl_readdir.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,31 @@
1818
*/
1919
const APIError = require("../../api/APIError");
2020
const { chkperm } = require("../../helpers");
21-
const { TYPE_DIRECTORY } = require("../FSNodeContext");
21+
const { TYPE_DIRECTORY, TYPE_SYMLINK } = require("../FSNodeContext");
2222
const { LLListUsers } = require("../ll_operations/ll_listusers");
2323
const { LLReadDir } = require("../ll_operations/ll_readdir");
2424
const { LLReadShares } = require("../ll_operations/ll_readshares");
2525
const { HLFilesystemOperation } = require("./definitions");
2626

2727
class HLReadDir extends HLFilesystemOperation {
2828
async _run () {
29-
const { subject, user, no_thumbs, no_assocs, actor } = this.values;
29+
const { subject: subject_let, user, no_thumbs, no_assocs, actor } = this.values;
30+
let subject = subject_let;
3031

3132
if ( ! await subject.exists() ) {
3233
throw APIError.create('subject_does_not_exist');
3334
}
3435

36+
if ( await subject.get('type') === TYPE_SYMLINK ) {
37+
const { context } = this;
38+
const svc_acl = context.get('services').get('acl');
39+
if ( ! await svc_acl.check(actor, subject, 'read') ) {
40+
throw await svc_acl.get_safe_acl_error(actor, subject, 'read');
41+
}
42+
const target = await subject.getTarget();
43+
subject = target;
44+
}
45+
3546
if ( await subject.get('type') !== TYPE_DIRECTORY ) {
3647
const { context } = this;
3748
const svc_acl = context.get('services').get('acl');

src/backend/src/filesystem/ll_operations/ll_readdir.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919
const APIError = require("../../api/APIError");
20+
const { TYPE_SYMLINK } = require("../FSNodeContext");
2021
const { RootNodeSelector } = require("../node/selectors");
2122
const { NodeUIDSelector, NodeChildSelector } = require("../node/selectors");
2223
const { LLFilesystemOperation } = require("./definitions");
2324

2425
class LLReadDir extends LLFilesystemOperation {
2526
async _run () {
2627
const { context } = this;
27-
const { subject, user, actor, no_acl } = this.values;
28+
const { subject: subject_let, user, actor, no_acl } = this.values;
29+
let subject = subject_let;
2830

2931
if ( ! await subject.exists() ) {
3032
throw APIError.create('subject_does_not_exist');
@@ -37,6 +39,18 @@ class LLReadDir extends LLFilesystemOperation {
3739
}
3840
}
3941

42+
// TODO: DRY ACL check here
43+
const subject_type = await subject.get('type');
44+
if ( subject_type === TYPE_SYMLINK ) {
45+
const target = await subject.getTarget();
46+
if ( ! no_acl ) {
47+
if ( ! await svc_acl.check(actor, target, 'list') ) {
48+
throw await svc_acl.get_safe_acl_error(actor, target, 'list');
49+
}
50+
}
51+
subject = target;
52+
}
53+
4054
const subject_uuid = await subject.get('uid');
4155

4256
const svc = context.get('services');

0 commit comments

Comments
 (0)