Merge feature/root-prompt-and-shallow-chmod
@@ -2,7 +2,8 @@
2
2
3
3
## installsystemdservice.sh
4
4
- bool_is_true(value) - Parses common truthy string values used for installer feature flags.
5
- FILEMANAGER_SERVICE_RUN_AS_ROOT - Optional installer env flag; when true, writes a root-running systemd unit (omits User=) and enables FILEMANAGER_LIST_ACCESS_CHMOD in the unit environment.
5
- confirm_root_service_mode() - Interactive installer prompt (`[y/N]`) that decides whether the service should run as root when no env override is provided.
6
- FILEMANAGER_SERVICE_RUN_AS_ROOT - Optional installer env override for non-interactive installs; when truthy, writes a root-running systemd unit (omits User=) and enables FILEMANAGER_LIST_ACCESS_CHMOD in the unit environment.
6
7
7
8
## server/index.js
8
9
- start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
@@ -86,7 +87,7 @@
86
87
- loadConfigAndRoots() - Loads config and effective roots together so route access checks stay consistent.
87
88
- parseOctalMode(rawValue, fallback) - Parses optional octal chmod mode overrides from environment variables and falls back to secure defaults when invalid.
88
89
- envFlagEnabled(name) - Boolean environment flag parser for file-route runtime feature toggles.
89
- applyRecursiveAccessChmod(startDir) - Best-effort recursive chmod pass used for Samba-style compatibility on folder-access requests; skips symlinks and continues past individual errors.
90
- applyListAccessChmod(startDir) - Best-effort shallow chmod pass for folder-access requests; updates the opened folder and its direct children only, skips symlinks, and continues past individual errors.
90
91
- resolveRootForUser(absPath, roots, user, config) - Resolves access for configured roots plus user-owned personal folder.
91
92
- resolveRootForUser(absPath, roots, user, config) - Allows admins to access orphaned user folders (deleted-account folders) under userPath.
92
93
- resolveRootForUser(absPath, roots, user, config) - Treats the local subtitle debug log directory as an admin-only read-only browse root for the debug menu.
@@ -103,7 +104,7 @@
103
104
- POST /api/files/folder-icon - Sets or clears a folder's explicit icon assignment; imagePath must have a cached thumbnail; write access required.
104
105
- GET /api/files/search - Fuzzy-searches all readable roots (and personal folder when configured) for files, returning ranked matches with path metadata.
105
106
- GET /api/files/list - Returns directory items including name/path/isDir plus size, mtime, and uploadedAt; uploadedAt comes from persisted `file_meta.uploaded_at` when present, otherwise it is backfilled from filesystem creation/change metadata and saved.
106
- GET /api/files/list - When FILEMANAGER_LIST_ACCESS_CHMOD=1, runs a best-effort recursive chmod on the opened folder before listing (defaults: dirs 0777, files 0666; overrides via FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE and FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE).
107
- GET /api/files/list - When FILEMANAGER_LIST_ACCESS_CHMOD=1, runs a best-effort shallow chmod on the opened folder before listing (opened folder + direct children only; defaults: dirs 0777, files 0666; overrides via FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE and FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE).
107
108
- GET /api/files/search-images - Fuzzy-searches readable roots for image files with ready thumbnails, returning capped results plus scan-truncation metadata for scalable global favicon selection.
108
109
- GET /api/files/global-favicon-image - Publicly serves the configured global favicon thumbnail file so browsers can load `<link rel="icon">` without auth headers.
109
110
- GET /api/files/global-favicon - Returns the configured global favicon source file path ({favicon:{filePath}} or {favicon:null}).
@@ -2,7 +2,8 @@2
2
3
## installsystemdservice.sh
3
## installsystemdservice.sh
4
- bool_is_true(value) - Parses common truthy string values used for installer feature flags.
4
- bool_is_true(value) - Parses common truthy string values used for installer feature flags.
5
- FILEMANAGER_SERVICE_RUN_AS_ROOT - Optional installer env flag; when true, writes a root-running systemd unit (omits User=) and enables FILEMANAGER_LIST_ACCESS_CHMOD in the unit environment.
5
- confirm_root_service_mode() - Interactive installer prompt (`[y/N]`) that decides whether the service should run as root when no env override is provided.
6
- FILEMANAGER_SERVICE_RUN_AS_ROOT - Optional installer env override for non-interactive installs; when truthy, writes a root-running systemd unit (omits User=) and enables FILEMANAGER_LIST_ACCESS_CHMOD in the unit environment.
6
7
7
## server/index.js
8
## server/index.js
8
- start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
9
- start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
@@ -86,7 +87,7 @@86
- loadConfigAndRoots() - Loads config and effective roots together so route access checks stay consistent.
87
- loadConfigAndRoots() - Loads config and effective roots together so route access checks stay consistent.
87
- parseOctalMode(rawValue, fallback) - Parses optional octal chmod mode overrides from environment variables and falls back to secure defaults when invalid.
88
- parseOctalMode(rawValue, fallback) - Parses optional octal chmod mode overrides from environment variables and falls back to secure defaults when invalid.
88
- envFlagEnabled(name) - Boolean environment flag parser for file-route runtime feature toggles.
89
- envFlagEnabled(name) - Boolean environment flag parser for file-route runtime feature toggles.
89
- applyRecursiveAccessChmod(startDir) - Best-effort recursive chmod pass used for Samba-style compatibility on folder-access requests; skips symlinks and continues past individual errors.
90
- applyListAccessChmod(startDir) - Best-effort shallow chmod pass for folder-access requests; updates the opened folder and its direct children only, skips symlinks, and continues past individual errors.
90
- resolveRootForUser(absPath, roots, user, config) - Resolves access for configured roots plus user-owned personal folder.
91
- resolveRootForUser(absPath, roots, user, config) - Resolves access for configured roots plus user-owned personal folder.
91
- resolveRootForUser(absPath, roots, user, config) - Allows admins to access orphaned user folders (deleted-account folders) under userPath.
92
- resolveRootForUser(absPath, roots, user, config) - Allows admins to access orphaned user folders (deleted-account folders) under userPath.
92
- resolveRootForUser(absPath, roots, user, config) - Treats the local subtitle debug log directory as an admin-only read-only browse root for the debug menu.
93
- resolveRootForUser(absPath, roots, user, config) - Treats the local subtitle debug log directory as an admin-only read-only browse root for the debug menu.
@@ -103,7 +104,7 @@103
- POST /api/files/folder-icon - Sets or clears a folder's explicit icon assignment; imagePath must have a cached thumbnail; write access required.
104
- POST /api/files/folder-icon - Sets or clears a folder's explicit icon assignment; imagePath must have a cached thumbnail; write access required.
104
- GET /api/files/search - Fuzzy-searches all readable roots (and personal folder when configured) for files, returning ranked matches with path metadata.
105
- GET /api/files/search - Fuzzy-searches all readable roots (and personal folder when configured) for files, returning ranked matches with path metadata.
105
- GET /api/files/list - Returns directory items including name/path/isDir plus size, mtime, and uploadedAt; uploadedAt comes from persisted `file_meta.uploaded_at` when present, otherwise it is backfilled from filesystem creation/change metadata and saved.
106
- GET /api/files/list - Returns directory items including name/path/isDir plus size, mtime, and uploadedAt; uploadedAt comes from persisted `file_meta.uploaded_at` when present, otherwise it is backfilled from filesystem creation/change metadata and saved.
106
- GET /api/files/list - When FILEMANAGER_LIST_ACCESS_CHMOD=1, runs a best-effort recursive chmod on the opened folder before listing (defaults: dirs 0777, files 0666; overrides via FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE and FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE).
107
- GET /api/files/list - When FILEMANAGER_LIST_ACCESS_CHMOD=1, runs a best-effort shallow chmod on the opened folder before listing (opened folder + direct children only; defaults: dirs 0777, files 0666; overrides via FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE and FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE).
107
- GET /api/files/search-images - Fuzzy-searches readable roots for image files with ready thumbnails, returning capped results plus scan-truncation metadata for scalable global favicon selection.
108
- GET /api/files/search-images - Fuzzy-searches readable roots for image files with ready thumbnails, returning capped results plus scan-truncation metadata for scalable global favicon selection.
108
- GET /api/files/global-favicon-image - Publicly serves the configured global favicon thumbnail file so browsers can load `<link rel="icon">` without auth headers.
109
- GET /api/files/global-favicon-image - Publicly serves the configured global favicon thumbnail file so browsers can load `<link rel="icon">` without auth headers.
109
- GET /api/files/global-favicon - Returns the configured global favicon source file path ({favicon:{filePath}} or {favicon:null}).
110
- GET /api/files/global-favicon - Returns the configured global favicon source file path ({favicon:{filePath}} or {favicon:null}).
@@ -47,7 +47,7 @@
47
47
- `GET /api/files/thumbnail`
48
48
- `GET /api/files/root-access`
49
49
- `orphaned user folder access`
50
- `list access recursive chmod`
50
- `list access chmod`
51
51
- `subtitle debug cache access`
52
52
- `folder icon endpoints`
53
53
- `file search endpoint`
@@ -47,7 +47,7 @@47
- `GET /api/files/thumbnail`47
- `GET /api/files/thumbnail`48
- `GET /api/files/root-access`48
- `GET /api/files/root-access`49
- `orphaned user folder access`49
- `orphaned user folder access`50
- `list access recursive chmod`50
- `list access chmod`51
- `subtitle debug cache access`51
- `subtitle debug cache access`52
- `folder icon endpoints`52
- `folder icon endpoints`53
- `file search endpoint`53
- `file search endpoint`@@ -19,7 +19,7 @@ KNOWN_PACKAGE_MANAGERS=(apt-get apt dnf yum pacman zypper apk)
19
19
# Resolve the user who owns the project directory (i.e. the user who cloned it,
20
20
# not root). Falls back to the SUDO_USER env var, then 'pi'.
21
21
RUN_AS="${SUDO_USER:-pi}"
22
SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT:-0}"
22
SERVICE_RUN_AS_ROOT=""
23
23
24
24
bool_is_true() {
25
25
case "${1,,}" in
@@ -32,6 +32,32 @@ bool_is_true() {
32
32
esac
33
33
}
34
34
35
confirm_root_service_mode() {
36
if [[ ! -t 0 ]]; then
37
echo "[install] Non-interactive shell detected; defaulting to non-root service mode." >&2
38
return 1
39
fi
40
41
local reply
42
read -r -p "[install] Run the filemanager service as root? [y/N] " reply
43
case "${reply,,}" in
44
y|yes)
45
return 0
46
;;
47
*)
48
return 1
49
;;
50
esac
51
}
52
53
if [[ -n "${FILEMANAGER_SERVICE_RUN_AS_ROOT:-}" ]]; then
54
SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT}"
55
elif confirm_root_service_mode; then
56
SERVICE_RUN_AS_ROOT="1"
57
else
58
SERVICE_RUN_AS_ROOT="0"
59
fi
60
35
61
SERVICE_USER_LINE="User=${RUN_AS}"
36
62
SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'
37
63
SERVICE_ENV_LINE=""
@@ -45,7 +71,7 @@ fi
45
71
echo "[install] Project directory : $SCRIPT_DIR"
46
72
if bool_is_true "$SERVICE_RUN_AS_ROOT"; then
47
73
echo "[install] Service will run as root (FILEMANAGER_SERVICE_RUN_AS_ROOT=1)."
48
echo "[install] Enabling recursive chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"
74
echo "[install] Enabling chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"
49
75
else
50
76
echo "[install] Service will run as user: $RUN_AS"
51
77
fi
@@ -19,7 +19,7 @@ KNOWN_PACKAGE_MANAGERS=(apt-get apt dnf yum pacman zypper apk)19
# Resolve the user who owns the project directory (i.e. the user who cloned it,19
# Resolve the user who owns the project directory (i.e. the user who cloned it,20
# not root). Falls back to the SUDO_USER env var, then 'pi'.20
# not root). Falls back to the SUDO_USER env var, then 'pi'.21
RUN_AS="${SUDO_USER:-pi}"21
RUN_AS="${SUDO_USER:-pi}"22
SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT:-0}"22
SERVICE_RUN_AS_ROOT=""23
23
24
bool_is_true() {24
bool_is_true() {25
case "${1,,}" in25
case "${1,,}" in@@ -32,6 +32,32 @@ bool_is_true() {32
esac32
esac33
}33
}34
34
35
confirm_root_service_mode() {36
if [[ ! -t 0 ]]; then37
echo "[install] Non-interactive shell detected; defaulting to non-root service mode." >&238
return 139
fi40
41
local reply42
read -r -p "[install] Run the filemanager service as root? [y/N] " reply43
case "${reply,,}" in44
y|yes)45
return 046
;;47
*)48
return 149
;;50
esac51
}52
53
if [[ -n "${FILEMANAGER_SERVICE_RUN_AS_ROOT:-}" ]]; then54
SERVICE_RUN_AS_ROOT="${FILEMANAGER_SERVICE_RUN_AS_ROOT}"55
elif confirm_root_service_mode; then56
SERVICE_RUN_AS_ROOT="1"57
else58
SERVICE_RUN_AS_ROOT="0"59
fi60
35
SERVICE_USER_LINE="User=${RUN_AS}"61
SERVICE_USER_LINE="User=${RUN_AS}"36
SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'62
SERVICE_CAPABILITY_LINES=$'AmbientCapabilities=CAP_NET_BIND_SERVICE\nCapabilityBoundingSet=CAP_NET_BIND_SERVICE'37
SERVICE_ENV_LINE=""63
SERVICE_ENV_LINE=""@@ -45,7 +71,7 @@ fi45
echo "[install] Project directory : $SCRIPT_DIR"71
echo "[install] Project directory : $SCRIPT_DIR"46
if bool_is_true "$SERVICE_RUN_AS_ROOT"; then72
if bool_is_true "$SERVICE_RUN_AS_ROOT"; then47
echo "[install] Service will run as root (FILEMANAGER_SERVICE_RUN_AS_ROOT=1)."73
echo "[install] Service will run as root (FILEMANAGER_SERVICE_RUN_AS_ROOT=1)."48
echo "[install] Enabling recursive chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"74
echo "[install] Enabling chmod-on-folder-list via FILEMANAGER_LIST_ACCESS_CHMOD=1"49
else75
else50
echo "[install] Service will run as user: $RUN_AS"76
echo "[install] Service will run as user: $RUN_AS"51
fi77
fi@@ -200,50 +200,63 @@ function envFlagEnabled (name)
200
200
return value === '1' || value === 'true' || value === 'yes' || value === 'on';
201
201
}
202
202
203
function applyRecursiveAccessChmod (startDir)
203
function applyListAccessChmod (startDir)
204
204
{
205
205
const dirMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE, 0o777);
206
206
const fileMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE, 0o666);
207
const queue = [path.resolve(startDir)];
207
const rootDir = path.resolve(startDir);
208
208
209
while (queue.length)
209
let rootStat;
210
try
211
{
212
rootStat = fs.lstatSync(rootDir);
213
} catch
210
214
{
211
const current = queue.pop();
212
if (!current) continue;
215
return;
216
}
213
217
214
let stat;
215
try
216
{
217
stat = fs.lstatSync(current);
218
} catch
219
{
220
continue;
221
}
218
if (rootStat.isSymbolicLink()) return;
219
220
try
221
{
222
fs.chmodSync(rootDir, rootStat.isDirectory() ? dirMode : fileMode);
223
} catch
224
{
225
// Continue best-effort; listing should still work when possible.
226
}
222
227
223
if (stat.isSymbolicLink()) continue;
228
if (!rootStat.isDirectory()) return;
224
229
230
let entries = [];
231
try
232
{
233
entries = fs.readdirSync(rootDir, { withFileTypes: true });
234
} catch
235
{
236
return;
237
}
238
239
for (const entry of entries)
240
{
241
const childPath = path.join(rootDir, entry.name);
242
243
let childStat;
225
244
try
226
245
{
227
fs.chmodSync(current, stat.isDirectory() ? dirMode : fileMode);
246
childStat = fs.lstatSync(childPath);
228
247
} catch
229
248
{
230
// Continue best-effort; listing should still work when possible.
249
continue;
231
250
}
232
251
233
if (!stat.isDirectory()) continue;
252
if (childStat.isSymbolicLink()) continue;
234
253
235
let entries = [];
236
254
try
237
255
{
238
entries = fs.readdirSync(current, { withFileTypes: true });
256
fs.chmodSync(childPath, childStat.isDirectory() ? dirMode : fileMode);
239
257
} catch
240
258
{
241
continue;
242
}
243
244
for (const entry of entries)
245
{
246
queue.push(path.join(current, entry.name));
259
// Continue best-effort; listing should still work when possible.
247
260
}
248
261
}
249
262
}
@@ -1113,10 +1126,10 @@ router.get('/list', requireAuth, (req, res) =>
1113
1126
{
1114
1127
try
1115
1128
{
1116
applyRecursiveAccessChmod(dir);
1129
applyListAccessChmod(dir);
1117
1130
} catch (err)
1118
1131
{
1119
logError('Best-effort chmod pass failed before directory listing.', err, { dir: String(dir || '') });
1132
logError('Best-effort shallow chmod pass failed before directory listing.', err, { dir: String(dir || '') });
1120
1133
}
1121
1134
}
1122
1135
@@ -200,50 +200,63 @@ function envFlagEnabled (name)200
return value === '1' || value === 'true' || value === 'yes' || value === 'on';200
return value === '1' || value === 'true' || value === 'yes' || value === 'on';201
}201
}202
202
203
function applyRecursiveAccessChmod (startDir)203
function applyListAccessChmod (startDir)204
{204
{205
const dirMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE, 0o777);205
const dirMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_DIR_MODE, 0o777);206
const fileMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE, 0o666);206
const fileMode = parseOctalMode(process.env.FILEMANAGER_LIST_ACCESS_CHMOD_FILE_MODE, 0o666);207
const queue = [path.resolve(startDir)];207
const rootDir = path.resolve(startDir);208
208
209
while (queue.length)209
let rootStat;210
try211
{212
rootStat = fs.lstatSync(rootDir);213
} catch210
{214
{211
const current = queue.pop();215
return;212
if (!current) continue;216
}213
217
214
let stat;218
if (rootStat.isSymbolicLink()) return;215
try219
216
{220
try217
stat = fs.lstatSync(current);221
{218
} catch222
fs.chmodSync(rootDir, rootStat.isDirectory() ? dirMode : fileMode);219
{223
} catch220
continue;224
{221
}225
// Continue best-effort; listing should still work when possible.226
}222
227
223
if (stat.isSymbolicLink()) continue;228
if (!rootStat.isDirectory()) return;224
229
230
let entries = [];231
try232
{233
entries = fs.readdirSync(rootDir, { withFileTypes: true });234
} catch235
{236
return;237
}238
239
for (const entry of entries)240
{241
const childPath = path.join(rootDir, entry.name);242
243
let childStat;225
try244
try226
{245
{227
fs.chmodSync(current, stat.isDirectory() ? dirMode : fileMode);246
childStat = fs.lstatSync(childPath);228
} catch247
} catch229
{248
{230
// Continue best-effort; listing should still work when possible.249
continue;231
}250
}232
251
233
if (!stat.isDirectory()) continue;252
if (childStat.isSymbolicLink()) continue;234
253
235
let entries = [];236
try254
try237
{255
{238
entries = fs.readdirSync(current, { withFileTypes: true });256
fs.chmodSync(childPath, childStat.isDirectory() ? dirMode : fileMode);239
} catch257
} catch240
{258
{241
continue;259
// Continue best-effort; listing should still work when possible.242
}243
244
for (const entry of entries)245
{246
queue.push(path.join(current, entry.name));247
}260
}248
}261
}249
}262
}@@ -1113,10 +1126,10 @@ router.get('/list', requireAuth, (req, res) =>1113
{1126
{1114
try1127
try1115
{1128
{1116
applyRecursiveAccessChmod(dir);1129
applyListAccessChmod(dir);1117
} catch (err)1130
} catch (err)1118
{1131
{1119
logError('Best-effort chmod pass failed before directory listing.', err, { dir: String(dir || '') });1132
logError('Best-effort shallow chmod pass failed before directory listing.', err, { dir: String(dir || '') });1120
}1133
}1121
}1134
}1122
1135
@@ -689,18 +689,24 @@ describe('orphaned user folder access', () =>
689
689
});
690
690
});
691
691
692
describe('list access recursive chmod', () =>
692
describe('list access chmod', () =>
693
693
{
694
test('GET /api/files/list applies recursive chmod when enabled', async () =>
694
test('GET /api/files/list applies chmod to opened folder and direct children when enabled', async () =>
695
695
{
696
696
const nestedDir = path.join(rootDir, 'locked');
697
697
const nestedFile = path.join(nestedDir, 'data.txt');
698
const deepDir = path.join(nestedDir, 'deep');
699
const deepFile = path.join(deepDir, 'deep.txt');
698
700
fs.mkdirSync(nestedDir, { recursive: true });
701
fs.mkdirSync(deepDir, { recursive: true });
699
702
fs.writeFileSync(nestedFile, 'hello');
703
fs.writeFileSync(deepFile, 'deep');
700
704
701
705
fs.chmodSync(rootDir, 0o700);
702
706
fs.chmodSync(nestedDir, 0o700);
703
707
fs.chmodSync(nestedFile, 0o600);
708
fs.chmodSync(deepDir, 0o700);
709
fs.chmodSync(deepFile, 0o600);
704
710
705
711
process.env.FILEMANAGER_LIST_ACCESS_CHMOD = '1';
706
712
@@ -710,10 +716,14 @@ describe('list access recursive chmod', () =>
710
716
const rootMode = fs.statSync(rootDir).mode & 0o777;
711
717
const dirMode = fs.statSync(nestedDir).mode & 0o777;
712
718
const fileMode = fs.statSync(nestedFile).mode & 0o777;
719
const deepDirMode = fs.statSync(deepDir).mode & 0o777;
720
const deepFileMode = fs.statSync(deepFile).mode & 0o777;
713
721
714
722
expect(rootMode).toBe(0o777);
715
723
expect(dirMode).toBe(0o777);
716
expect(fileMode).toBe(0o666);
724
expect(fileMode).toBe(0o600);
725
expect(deepDirMode).toBe(0o700);
726
expect(deepFileMode).toBe(0o600);
717
727
});
718
728
719
729
test('GET /api/files/list leaves permissions unchanged when disabled', async () =>
@@ -689,18 +689,24 @@ describe('orphaned user folder access', () =>689
});689
});690
});690
});691
691
692
describe('list access recursive chmod', () =>692
describe('list access chmod', () =>693
{693
{694
test('GET /api/files/list applies recursive chmod when enabled', async () =>694
test('GET /api/files/list applies chmod to opened folder and direct children when enabled', async () =>695
{695
{696
const nestedDir = path.join(rootDir, 'locked');696
const nestedDir = path.join(rootDir, 'locked');697
const nestedFile = path.join(nestedDir, 'data.txt');697
const nestedFile = path.join(nestedDir, 'data.txt');698
const deepDir = path.join(nestedDir, 'deep');699
const deepFile = path.join(deepDir, 'deep.txt');698
fs.mkdirSync(nestedDir, { recursive: true });700
fs.mkdirSync(nestedDir, { recursive: true });701
fs.mkdirSync(deepDir, { recursive: true });699
fs.writeFileSync(nestedFile, 'hello');702
fs.writeFileSync(nestedFile, 'hello');703
fs.writeFileSync(deepFile, 'deep');700
704
701
fs.chmodSync(rootDir, 0o700);705
fs.chmodSync(rootDir, 0o700);702
fs.chmodSync(nestedDir, 0o700);706
fs.chmodSync(nestedDir, 0o700);703
fs.chmodSync(nestedFile, 0o600);707
fs.chmodSync(nestedFile, 0o600);708
fs.chmodSync(deepDir, 0o700);709
fs.chmodSync(deepFile, 0o600);704
710
705
process.env.FILEMANAGER_LIST_ACCESS_CHMOD = '1';711
process.env.FILEMANAGER_LIST_ACCESS_CHMOD = '1';706
712
@@ -710,10 +716,14 @@ describe('list access recursive chmod', () =>710
const rootMode = fs.statSync(rootDir).mode & 0o777;716
const rootMode = fs.statSync(rootDir).mode & 0o777;711
const dirMode = fs.statSync(nestedDir).mode & 0o777;717
const dirMode = fs.statSync(nestedDir).mode & 0o777;712
const fileMode = fs.statSync(nestedFile).mode & 0o777;718
const fileMode = fs.statSync(nestedFile).mode & 0o777;719
const deepDirMode = fs.statSync(deepDir).mode & 0o777;720
const deepFileMode = fs.statSync(deepFile).mode & 0o777;713
721
714
expect(rootMode).toBe(0o777);722
expect(rootMode).toBe(0o777);715
expect(dirMode).toBe(0o777);723
expect(dirMode).toBe(0o777);716
expect(fileMode).toBe(0o666);724
expect(fileMode).toBe(0o600);725
expect(deepDirMode).toBe(0o700);726
expect(deepFileMode).toBe(0o600);717
});727
});718
728
719
test('GET /api/files/list leaves permissions unchanged when disabled', async () =>729
test('GET /api/files/list leaves permissions unchanged when disabled', async () =>