Skip to content

Commit

Permalink
feat: support readdir for directory symlinks
Browse files Browse the repository at this point in the history
KernelDeimos committed Oct 8, 2024

Verified

This commit was signed with the committer’s verified signature.
edalzell Erin Dalzell
1 parent c2a9506 commit 7f1b870
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/backend/src/filesystem/hl_operations/hl_readdir.js
Original file line number Diff line number Diff line change
@@ -18,20 +18,31 @@
*/
const APIError = require("../../api/APIError");
const { chkperm } = require("../../helpers");
const { TYPE_DIRECTORY } = require("../FSNodeContext");
const { TYPE_DIRECTORY, TYPE_SYMLINK } = require("../FSNodeContext");
const { LLListUsers } = require("../ll_operations/ll_listusers");
const { LLReadDir } = require("../ll_operations/ll_readdir");
const { LLReadShares } = require("../ll_operations/ll_readshares");
const { HLFilesystemOperation } = require("./definitions");

class HLReadDir extends HLFilesystemOperation {
async _run () {
const { subject, user, no_thumbs, no_assocs, actor } = this.values;
const { subject: subject_let, user, no_thumbs, no_assocs, actor } = this.values;
let subject = subject_let;

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

if ( await subject.get('type') === TYPE_SYMLINK ) {
const { context } = this;
const svc_acl = context.get('services').get('acl');
if ( ! await svc_acl.check(actor, subject, 'read') ) {
throw await svc_acl.get_safe_acl_error(actor, subject, 'read');
}
const target = await subject.getTarget();
subject = target;
}

if ( await subject.get('type') !== TYPE_DIRECTORY ) {
const { context } = this;
const svc_acl = context.get('services').get('acl');
16 changes: 15 additions & 1 deletion src/backend/src/filesystem/ll_operations/ll_readdir.js
Original file line number Diff line number Diff line change
@@ -17,14 +17,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const APIError = require("../../api/APIError");
const { TYPE_SYMLINK } = require("../FSNodeContext");
const { RootNodeSelector } = require("../node/selectors");
const { NodeUIDSelector, NodeChildSelector } = require("../node/selectors");
const { LLFilesystemOperation } = require("./definitions");

class LLReadDir extends LLFilesystemOperation {
async _run () {
const { context } = this;
const { subject, user, actor, no_acl } = this.values;
const { subject: subject_let, user, actor, no_acl } = this.values;
let subject = subject_let;

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

// TODO: DRY ACL check here
const subject_type = await subject.get('type');
if ( subject_type === TYPE_SYMLINK ) {
const target = await subject.getTarget();
if ( ! no_acl ) {
if ( ! await svc_acl.check(actor, target, 'list') ) {
throw await svc_acl.get_safe_acl_error(actor, target, 'list');
}
}
subject = target;
}

const subject_uuid = await subject.get('uid');

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

0 comments on commit 7f1b870

Please sign in to comment.