diff --git a/apps/ll-cli/src/main.cpp b/apps/ll-cli/src/main.cpp index 61eb25d50..bac4f62dc 100644 --- a/apps/ll-cli/src/main.cpp +++ b/apps/ll-cli/src/main.cpp @@ -150,10 +150,11 @@ int lockCheck() noexcept ::close(fd); }); - struct flock lock_info - { - .l_type = F_RDLCK, .l_whence = SEEK_SET, .l_start = 0, .l_len = 0, .l_pid = 0 - }; + struct flock lock_info{ .l_type = F_RDLCK, + .l_whence = SEEK_SET, + .l_start = 0, + .l_len = 0, + .l_pid = 0 }; if (::fcntl(fd, F_GETLK, &lock_info) == -1) { qCritical() << "failed to get lock" << lock; @@ -556,6 +557,18 @@ ll-cli list --upgradable auto userContainerDir = std::filesystem::path{ "/run/linglong" } / std::to_string(::getuid()); ensureDirectory(userContainerDir); + auto removeIfEmpty = linglong::utils::finally::finally([&userContainerDir] { + std::error_code ec; + if (!std::filesystem::remove(userContainerDir, ec) && ec) { + if (ec == std::errc::directory_not_empty + || ec == std::errc::no_such_file_or_directory) { + return; + } + + qWarning() << "failed to remove" << userContainerDir.c_str() << ":" + << ec.message().c_str(); + } + }); while (true) { auto lockOwner = lockCheck();