Skip to content

Commit

Permalink
feat: remove runtime directory if it's empty
Browse files Browse the repository at this point in the history
Signed-off-by: ComixHe <[email protected]>
  • Loading branch information
ComixHe committed Jan 16, 2025
1 parent 499cc11 commit ed0756e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions apps/ll-cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit ed0756e

Please sign in to comment.