Skip to content

Commit 7eca152

Browse files
committed
fixed delete method and build package
1 parent f753d47 commit 7eca152

8 files changed

Lines changed: 107 additions & 35 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## Cockpit Navigator 0.5.11-3
1+
## Cockpit Navigator 0.5.11-4
22

3-
* build package + fixed deletion method of tmp files
3+
* build package

manifest.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"title": "Cockpit Navigator",
55
"description": "A File System Browser for Cockpit.",
66
"version": "0.5.11",
7-
"build_number": "3",
7+
"build_number": "4",
88
"stable": false,
99
"author": "Josh Boudreau <jboudreau@45drives.com>",
1010
"git_url": "https://github.com/45Drives/cockpit-navigator",
@@ -32,8 +32,7 @@
3232
"rsync",
3333
"zip",
3434
"file",
35-
"/bin/mkdir",
36-
"/bin/rmdir",
35+
"coreutils",
3736
"inotify-tools"
3837
]
3938
},
@@ -71,7 +70,7 @@
7170
"changelog": {
7271
"urgency": "medium",
7372
"version": "0.5.11",
74-
"build_number": "3",
73+
"build_number": "4",
7574
"date": null,
7675
"packager": "Josh Boudreau <jboudreau@45drives.com>",
7776
"changes": []

navigator/components/NavContextMenu.js

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class NavContextMenu {
137137
});
138138
}
139139

140-
async download(e) {
140+
async download(e) {
141141
let download_target = "";
142142
let result; // function-scoped so we can reference later
143143

@@ -158,34 +158,85 @@ export class NavContextMenu {
158158
this.nav_window_ref.stop_load();
159159
}
160160
}
161-
if (result?.["archive-path"]) {
162-
const unitName = `nav-clean-on-open-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;
163-
const script = [
164-
'set -euo pipefail',
165-
'if ! command -v inotifywait >/dev/null 2>&1; then ' +
166-
'sleep 300; rm -f -- "$ARCHIVE"; ' +
167-
'[ -n "${TEMPDIR:-}" ] && [[ "$TEMPDIR" == /tmp/navigator-* ]] && rm -rf -- "$TEMPDIR"; ' +
168-
'exit 0; fi',
169-
'inotifywait -q -t 1800 -e open -- "$ARCHIVE" || true',
170-
'rm -f -- "$ARCHIVE"',
171-
'sleep 3600',
172-
'[ -n "${TEMPDIR:-}" ] && [[ "$TEMPDIR" == /tmp/navigator-* ]] && rm -rf -- "$TEMPDIR" || :'
173-
].join(' && ');
174-
const cmd = [
175-
'systemd-run',
176-
'--property=CollectMode=inactive-or-failed',
177-
'--property=RuntimeMaxSec=90000',
178-
'--unit', unitName,
179-
'--setenv=ARCHIVE=' + result['archive-path'],
180-
...(result['temp-dir'] ? ['--setenv=TEMPDIR=' + result['temp-dir']] : []),
181-
'/bin/bash','-lc', script
182-
];
183-
184-
await cockpit.spawn(cmd, { superuser: 'require', err: 'out' }).then(out => console.log(out));
185-
console.log("scheduled cleanup:", unitName);
186-
console.log("Deleting :", result['archive-path'], "in 30 minutes or after download starts.");
187-
}
188-
161+
if (result?.["archive-path"]) {
162+
const unitName = `nav-clean-sweep-on-close-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;
163+
164+
const script = `
165+
set -euo pipefail
166+
167+
ARCHIVE="$ARCHIVE"
168+
DIR="$(dirname -- "$ARCHIVE")"
169+
BASE="$(basename -- "$ARCHIVE")"
170+
ROOT="/tmp/navigator"
171+
PATTERN="navigator-download*"
172+
173+
if ! command -v inotifywait >/dev/null 2>&1; then
174+
sleep 300
175+
rm -f -- "$ARCHIVE" || true
176+
# Sweep everything matching PATTERN that's not in use
177+
find "$ROOT" -mindepth 1 -maxdepth 1 -name "$PATTERN" -print0 | \
178+
while IFS= read -r -d '' p; do
179+
if command -v lsof >/dev/null 2>&1 && lsof -t -- "$p" >/dev/null 2>&1; then
180+
continue
181+
fi
182+
rm -rf -- "$p"
183+
done
184+
[ -n "\${TEMPDIR:-}" ] && [[ "$TEMPDIR" == /tmp/navigator-* ]] && rm -rf -- "$TEMPDIR" || :
185+
exit 0
186+
fi
187+
188+
if ! timeout 1800 bash -lc '
189+
inotifywait -q -m -e open --format "%e %f" -- "$DIR" |
190+
while read ev f; do
191+
if [ "$f" = "$BASE" ]; then exit 0; fi
192+
done
193+
'; then
194+
find "$ROOT" -mindepth 1 -maxdepth 1 -name "$PATTERN" -print0 | \
195+
while IFS= read -r -d '' p; do
196+
if command -v lsof >/dev/null 2>&1 && lsof -t -- "$p" >/dev/null 2>&1; then
197+
continue
198+
fi
199+
rm -rf -- "$p"
200+
done
201+
exit 0
202+
fi
203+
204+
if command -v lsof >/dev/null 2>&1; then
205+
# Ensure no process holds ARCHIVE open
206+
sleep 1
207+
while lsof -t -- "$ARCHIVE" >/dev/null 2>&1; do sleep 1; done
208+
else
209+
timeout 86400 bash -lc '
210+
inotifywait -q -m -e close --format "%e %f" -- "$DIR" |
211+
while read ev f; do
212+
if [ "$f" = "$BASE" ]; then exit 0; fi
213+
done
214+
' || true
215+
fi
216+
217+
rm -f -- "$ARCHIVE" || true
218+
219+
# (uncomment -mmin +5 to keep very fresh ones)
220+
find "$ROOT" -mindepth 1 -maxdepth 1 -name "$PATTERN" -print0 | \
221+
while IFS= read -r -d '' p; do
222+
if command -v lsof >/dev/null 2>&1 && lsof -t -- "$p" >/dev/null 2>&1; then
223+
continue
224+
fi
225+
rm -rf -- "$p"
226+
done
227+
[ -n "\${TEMPDIR:-}" ] && [[ "$TEMPDIR" == /tmp/navigator-* ]] && rm -rf -- "$TEMPDIR" || :
228+
`;
229+
const cmd = [
230+
'systemd-run',
231+
'--property=CollectMode=inactive-or-failed',
232+
'--property=RuntimeMaxSec=90000',
233+
'--unit', unitName,
234+
'--setenv=ARCHIVE=' + result['archive-path'],
235+
...(result['temp-dir'] ? ['--setenv=TEMPDIR=' + result['temp-dir']] : []),
236+
'/bin/bash','-lc', script
237+
];
238+
await cockpit.spawn(cmd, { superuser: 'require', err: 'out' });
239+
}
189240
const downloader = new NavDownloader(download_target);
190241
downloader.download();
191242
}

packaging/debian-bookworm/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
cockpit-navigator (0.5.11-4bookworm) bookworm; urgency=medium
2+
3+
* build package
4+
5+
-- Rachit Hans <rhans@45drives.com> Tue, 16 Sep 2025 11:58:45 -0300
6+
17
cockpit-navigator (0.5.11-3bookworm) bookworm; urgency=medium
28

39
* build package + fixed deletion method of tmp files

packaging/rocky-el8/main.spec.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ rm -rf %{buildroot}
3333
/usr/share/cockpit/navigator/*
3434

3535
%changelog
36+
* Tue Sep 16 2025 Rachit Hans <rhans@45drives.com> 0.5.11-4
37+
- build package
3638
* Tue Sep 16 2025 Rachit Hans <rhans@45drives.com> 0.5.11-3
3739
- build package + fixed deletion method of tmp files
3840
* Tue Sep 16 2025 Jordan Keough <jkeough@45drives.com> 0.5.11-2

packaging/rocky-el9/main.spec.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ rm -rf %{buildroot}
3333
/usr/share/cockpit/navigator/*
3434

3535
%changelog
36+
* Tue Sep 16 2025 Rachit Hans <rhans@45drives.com> 0.5.11-4
37+
- build package
3638
* Tue Sep 16 2025 Rachit Hans <rhans@45drives.com> 0.5.11-3
3739
- build package + fixed deletion method of tmp files
3840
* Tue Sep 16 2025 Jordan Keough <jkeough@45drives.com> 0.5.11-2

packaging/ubuntu-focal/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
cockpit-navigator (0.5.11-4focal) focal; urgency=medium
2+
3+
* build package
4+
5+
-- Rachit Hans <rhans@45drives.com> Tue, 16 Sep 2025 11:58:45 -0300
6+
17
cockpit-navigator (0.5.11-3focal) focal; urgency=medium
28

39
* build package + fixed deletion method of tmp files

packaging/ubuntu-jammy/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
cockpit-navigator (0.5.11-4jammy) jammy; urgency=medium
2+
3+
* build package
4+
5+
-- Rachit Hans <rhans@45drives.com> Tue, 16 Sep 2025 11:58:45 -0300
6+
17
cockpit-navigator (0.5.11-3jammy) jammy; urgency=medium
28

39
* build package + fixed deletion method of tmp files

0 commit comments

Comments
 (0)