@@ -26,6 +26,24 @@ const { buffer_to_stream } = require("../../util/streamutil");
26
26
const { TYPE_SYMLINK , TYPE_DIRECTORY } = require ( "../FSNodeContext" ) ;
27
27
const { LLFilesystemOperation } = require ( "./definitions" ) ;
28
28
29
+ const dry_checks = [
30
+ async function check_ACL_for_read ( a ) {
31
+ if ( a . get ( 'no_acl' ) ) return ;
32
+ const context = a . iget ( 'context' ) ;
33
+ const svc_acl = context . get ( 'services' ) . get ( 'acl' ) ;
34
+ const { fsNode, actor } = a . values ( ) ;
35
+ if ( ! await svc_acl . check ( actor , fsNode , 'read' ) ) {
36
+ throw await svc_acl . get_safe_acl_error ( actor , fsNode , 'read' ) ;
37
+ }
38
+ } ,
39
+ async function type_check_for_read ( a ) {
40
+ const fsNode = a . get ( 'fsNode' ) ;
41
+ if ( await fsNode . get ( 'type' ) === TYPE_DIRECTORY ) {
42
+ throw APIError . create ( 'cannot_read_a_directory' ) ;
43
+ }
44
+ } ,
45
+ ] ;
46
+
29
47
class LLRead extends LLFilesystemOperation {
30
48
static METHODS = {
31
49
_run : new Sequence ( {
@@ -39,12 +57,7 @@ class LLRead extends LLFilesystemOperation {
39
57
throw APIError . create ( 'subject_does_not_exist' ) ;
40
58
}
41
59
} ,
42
- async function type_check_for_read ( a ) {
43
- const fsNode = a . get ( 'fsNode' ) ;
44
- if ( await fsNode . get ( 'type' ) === TYPE_DIRECTORY ) {
45
- throw APIError . create ( 'cannot_read_a_directory' ) ;
46
- }
47
- } ,
60
+ ...dry_checks ,
48
61
async function resolve_symlink ( a ) {
49
62
let fsNode = a . get ( 'fsNode' ) ;
50
63
let type = await fsNode . get ( 'type' ) ;
@@ -54,15 +67,7 @@ class LLRead extends LLFilesystemOperation {
54
67
}
55
68
a . set ( 'fsNode' , fsNode ) ;
56
69
} ,
57
- async function check_ACL_for_read ( a ) {
58
- if ( a . get ( 'no_acl' ) ) return ;
59
- const context = a . iget ( 'context' ) ;
60
- const svc_acl = context . get ( 'services' ) . get ( 'acl' ) ;
61
- const { fsNode, actor } = a . values ( ) ;
62
- if ( ! await svc_acl . check ( actor , fsNode , 'read' ) ) {
63
- throw await svc_acl . get_safe_acl_error ( actor , fsNode , 'read' ) ;
64
- }
65
- } ,
70
+ ...dry_checks ,
66
71
async function calculate_has_range ( a ) {
67
72
const { offset, length } = a . values ( ) ;
68
73
const fsNode = a . get ( 'fsNode' ) ;
0 commit comments