fix: replace shell-level lock polling with apt-get native lock waiting for ubuntu and debian (#63)

* fix: replace shell-level lock polling with apt-get native lock waiting for ubuntu and debian

* test: fix apt-get update assertion to include lock timeout flag
This commit is contained in:
M3shour
2026-03-25 12:14:52 +02:00
committed by GitHub
parent 0194d0a64f
commit f6691f3e05
3 changed files with 18 additions and 14 deletions

View File

@@ -60,9 +60,15 @@ describe('Script Generators', () => {
it('should generate apt install commands', () => {
const script = generateUbuntuScript([pkg]);
expect(script).toContain('sudo apt-get update');
expect(script).toContain('sudo apt-get -o DPkg::Lock::Timeout=60 update');
expect(script).toContain('install_pkg "Mock Official App" "mock-pkg"');
});
it('should use native apt lock waiting instead of wait_for_lock', () => {
const script = generateUbuntuScript([pkg]);
expect(script).toContain('DPkg::Lock::Timeout=60');
expect(script).not.toContain('wait_for_lock /var/lib/dpkg/lock-frontend');
});
});
describe('Flatpak Generator', () => {
@@ -74,4 +80,4 @@ describe('Script Generators', () => {
expect(script).toContain('install_pkg "Mock Official App" "org.mock.App"');
});
});
});
});

View File

@@ -18,7 +18,7 @@ install_pkg() {
local start=$(date +%s)
with_retry sudo apt-get install -y "$pkg" &
with_retry sudo apt-get -o DPkg::Lock::Timeout=60 install -y "$pkg" &
local pid=$!
if animate_progress "$name" $pid; then
@@ -30,8 +30,8 @@ install_pkg() {
printf "\\r\\033[K" >&3
if tail -n 50 "$LOG" | grep -q "unmet dependencies"; then
warn "Fixing dependencies for $name..."
if sudo apt-get --fix-broken install -y >/dev/null 2>&1; then
sudo apt-get install -y "$pkg" &
if sudo apt-get -o DPkg::Lock::Timeout=60 --fix-broken install -y >/dev/null 2>&1; then
sudo apt-get -o DPkg::Lock::Timeout=60 install -y "$pkg" &
if animate_progress "$name (retry)" $!; then
local elapsed=$(($(date +%s) - start))
success "$name" "\${elapsed}s, deps fixed"
@@ -53,11 +53,10 @@ info "Caching sudo credentials..."
sudo -v || exit 1
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
wait_for_lock /var/lib/dpkg/lock-frontend
sudo dpkg --configure -a >/dev/null 2>&1 || true
info "Updating package lists..."
with_retry sudo apt-get update -qq &
with_retry sudo apt-get -o DPkg::Lock::Timeout=60 update -qq &
if animate_progress "Updating..." $!; then
printf "\\r\\033[K" >&3
success "Updated"
@@ -74,4 +73,4 @@ ${packages.map(({ app, pkg }) => `install_pkg "${escapeShellString(app.name)}" "
print_summary
`;
}
}

View File

@@ -18,7 +18,7 @@ install_pkg() {
local start=$(date +%s)
with_retry sudo apt-get install -y "$pkg" &
with_retry sudo apt-get -o DPkg::Lock::Timeout=60 install -y "$pkg" &
local pid=$!
if animate_progress "$name" $pid; then
@@ -30,8 +30,8 @@ install_pkg() {
printf "\\r\\033[K" >&3
if tail -n 50 "$LOG" | grep -q "unmet dependencies"; then
warn "Fixing dependencies for $name..." >&3
if sudo apt-get --fix-broken install -y >/dev/null 2>&1; then
sudo apt-get install -y "$pkg" &
if sudo apt-get -o DPkg::Lock::Timeout=60 --fix-broken install -y >/dev/null 2>&1; then
sudo apt-get -o DPkg::Lock::Timeout=60 install -y "$pkg" &
if animate_progress "$name (retry)" $!; then
local elapsed=$(($(date +%s) - start))
success "$name" "\${elapsed}s, deps fixed"
@@ -53,11 +53,10 @@ info "Caching sudo credentials..."
sudo -v || exit 1
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
wait_for_lock /var/lib/dpkg/lock-frontend
sudo dpkg --configure -a >/dev/null 2>&1 || true
info "Updating package lists..."
with_retry sudo apt-get update -qq &
with_retry sudo apt-get -o DPkg::Lock::Timeout=60 update -qq &
if animate_progress "Updating..." $!; then
printf "\\r\\033[K" >&3
success "Updated"
@@ -74,4 +73,4 @@ ${packages.map(({ app, pkg }) => `install_pkg "${escapeShellString(app.name)}" "
print_summary
`;
}
}