mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-09-26 03:08:41 +02:00
fixed deletion process by delteing all tmp/navigator close/unsed files
This commit is contained in:
parent
c252a4097a
commit
9155fc3e10
@ -158,34 +158,85 @@ export class NavContextMenu {
|
|||||||
this.nav_window_ref.stop_load();
|
this.nav_window_ref.stop_load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result?.["archive-path"]) {
|
if (result?.["archive-path"]) {
|
||||||
const unitName = `nav-clean-on-open-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;
|
const unitName = `nav-clean-sweep-on-close-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;
|
||||||
const script = [
|
|
||||||
'set -euo pipefail',
|
const script = `
|
||||||
'if ! command -v inotifywait >/dev/null 2>&1; then ' +
|
set -euo pipefail
|
||||||
'sleep 300; rm -f -- "$ARCHIVE"; ' +
|
|
||||||
'[ -n "${TEMPDIR:-}" ] && [[ "$TEMPDIR" == /tmp/navigator-* ]] && rm -rf -- "$TEMPDIR"; ' +
|
ARCHIVE="$ARCHIVE"
|
||||||
'exit 0; fi',
|
DIR="$(dirname -- "$ARCHIVE")"
|
||||||
'inotifywait -q -t 1800 -e open -- "$ARCHIVE" || true',
|
BASE="$(basename -- "$ARCHIVE")"
|
||||||
'rm -f -- "$ARCHIVE"',
|
ROOT="/tmp/navigator"
|
||||||
'sleep 3600',
|
PATTERN="navigator-download*"
|
||||||
'[ -n "${TEMPDIR:-}" ] && [[ "$TEMPDIR" == /tmp/navigator-* ]] && rm -rf -- "$TEMPDIR" || :'
|
|
||||||
].join(' && ');
|
if ! command -v inotifywait >/dev/null 2>&1; then
|
||||||
const cmd = [
|
sleep 300
|
||||||
'systemd-run',
|
rm -f -- "$ARCHIVE" || true
|
||||||
'--property=CollectMode=inactive-or-failed',
|
# Sweep everything matching PATTERN that's not in use
|
||||||
'--property=RuntimeMaxSec=90000',
|
find "$ROOT" -mindepth 1 -maxdepth 1 -name "$PATTERN" -print0 | \
|
||||||
'--unit', unitName,
|
while IFS= read -r -d '' p; do
|
||||||
'--setenv=ARCHIVE=' + result['archive-path'],
|
if command -v lsof >/dev/null 2>&1 && lsof -t -- "$p" >/dev/null 2>&1; then
|
||||||
...(result['temp-dir'] ? ['--setenv=TEMPDIR=' + result['temp-dir']] : []),
|
continue
|
||||||
'/bin/bash','-lc', script
|
fi
|
||||||
];
|
rm -rf -- "$p"
|
||||||
|
done
|
||||||
await cockpit.spawn(cmd, { superuser: 'require', err: 'out' }).then(out => console.log(out));
|
[ -n "\${TEMPDIR:-}" ] && [[ "$TEMPDIR" == /tmp/navigator-* ]] && rm -rf -- "$TEMPDIR" || :
|
||||||
console.log("scheduled cleanup:", unitName);
|
exit 0
|
||||||
console.log("Deleting :", result['archive-path'], "in 30 minutes or after download starts.");
|
fi
|
||||||
}
|
|
||||||
|
if ! timeout 1800 bash -lc '
|
||||||
|
inotifywait -q -m -e open --format "%e %f" -- "$DIR" |
|
||||||
|
while read ev f; do
|
||||||
|
if [ "$f" = "$BASE" ]; then exit 0; fi
|
||||||
|
done
|
||||||
|
'; then
|
||||||
|
find "$ROOT" -mindepth 1 -maxdepth 1 -name "$PATTERN" -print0 | \
|
||||||
|
while IFS= read -r -d '' p; do
|
||||||
|
if command -v lsof >/dev/null 2>&1 && lsof -t -- "$p" >/dev/null 2>&1; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
rm -rf -- "$p"
|
||||||
|
done
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v lsof >/dev/null 2>&1; then
|
||||||
|
# Ensure no process holds ARCHIVE open
|
||||||
|
sleep 1
|
||||||
|
while lsof -t -- "$ARCHIVE" >/dev/null 2>&1; do sleep 1; done
|
||||||
|
else
|
||||||
|
timeout 86400 bash -lc '
|
||||||
|
inotifywait -q -m -e close --format "%e %f" -- "$DIR" |
|
||||||
|
while read ev f; do
|
||||||
|
if [ "$f" = "$BASE" ]; then exit 0; fi
|
||||||
|
done
|
||||||
|
' || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f -- "$ARCHIVE" || true
|
||||||
|
|
||||||
|
# (uncomment -mmin +5 to keep very fresh ones)
|
||||||
|
find "$ROOT" -mindepth 1 -maxdepth 1 -name "$PATTERN" -print0 | \
|
||||||
|
while IFS= read -r -d '' p; do
|
||||||
|
if command -v lsof >/dev/null 2>&1 && lsof -t -- "$p" >/dev/null 2>&1; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
rm -rf -- "$p"
|
||||||
|
done
|
||||||
|
[ -n "\${TEMPDIR:-}" ] && [[ "$TEMPDIR" == /tmp/navigator-* ]] && rm -rf -- "$TEMPDIR" || :
|
||||||
|
`;
|
||||||
|
const cmd = [
|
||||||
|
'systemd-run',
|
||||||
|
'--property=CollectMode=inactive-or-failed',
|
||||||
|
'--property=RuntimeMaxSec=90000',
|
||||||
|
'--unit', unitName,
|
||||||
|
'--setenv=ARCHIVE=' + result['archive-path'],
|
||||||
|
...(result['temp-dir'] ? ['--setenv=TEMPDIR=' + result['temp-dir']] : []),
|
||||||
|
'/bin/bash','-lc', script
|
||||||
|
];
|
||||||
|
await cockpit.spawn(cmd, { superuser: 'require', err: 'out' });
|
||||||
|
}
|
||||||
const downloader = new NavDownloader(download_target);
|
const downloader = new NavDownloader(download_target);
|
||||||
downloader.download();
|
downloader.download();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user