Skip to content

refactor: stage install files to cache before processing#1646

Draft
dengbo11 wants to merge 1 commit intoOpenAtom-Linyaps:masterfrom
dengbo11:fix-uab-path
Draft

refactor: stage install files to cache before processing#1646
dengbo11 wants to merge 1 commit intoOpenAtom-Linyaps:masterfrom
dengbo11:fix-uab-path

Conversation

@dengbo11
Copy link
Copy Markdown
Collaborator

Replace file descriptor-based approach with path-based approach for install file handling. Now the PackageManager stages incoming D-Bus file descriptors into a cache directory and passes the cached file path to subsequent processing. This ensures reliable file access throughout the installation pipeline, as file descriptors from D-Bus can be unreliable. Added CachedInstallFile RAII wrapper for automatic cache cleanup on destruction.

Log: Changed install file handling from file descriptor to cached file path approach for improved reliability

Influence:

  1. Test install from layer file with valid .layer file
  2. Test install from UAB file with valid .uab file
  3. Verify cached files are created in the cache directory
  4. Verify cached files are automatically cleaned up after installation
  5. Test with invalid file types and verify proper error handling
  6. Verify file descriptor leaks are prevented during installation
  7. Test that UAB installation hooks receive correct file path

Replace file descriptor-based approach with path-based approach for
install file handling. Now the PackageManager stages incoming D-Bus file
descriptors into a cache directory and passes the cached file path to
subsequent processing. This ensures reliable file access throughout the
installation pipeline, as file descriptors from D-Bus can be unreliable.
Added CachedInstallFile RAII wrapper for automatic cache cleanup on
destruction.

Log: Changed install file handling from file descriptor to cached file
path approach for improved reliability

Influence:
1. Test install from layer file with valid .layer file
2. Test install from UAB file with valid .uab file
3. Verify cached files are created in the cache directory
4. Verify cached files are automatically cleaned up after installation
5. Test with invalid file types and verify proper error handling
6. Verify file descriptor leaks are prevented during installation
7. Test that UAB installation hooks receive correct file path
@deepin-ci-robot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengbo11

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dengbo11 dengbo11 closed this Apr 23, 2026
@dengbo11 dengbo11 reopened this Apr 23, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the package installation process to use path-based file handling instead of raw file descriptors. It introduces a CachedInstallFile class to manage temporary staged files and updates UABFile and InstallHookManager to operate on file paths. Feedback is provided regarding potential infinite loops in the file reading and writing logic where return values of 0 (EOF or no bytes written) are not explicitly handled.

Comment on lines +346 to 350
auto readBytes = this->read(reinterpret_cast<char *>(buf.data()), bytesRead);
if (readBytes == -1) {
if (errno == EINTR) {
errno = 0;
continue;
}
return LINGLONG_ERR(
fmt::format("read from sign section error: {}", common::error::errorString(errno)));
fmt::format("read from sign section error: {}", this->errorString().toStdString()));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If this->read returns 0 (EOF) before totalBytes is reached, the loop will hang indefinitely because totalBytes is never decremented. You should check for an unexpected EOF and return an error.

        auto readBytes = this->read(reinterpret_cast<char *>(buf.data()), bytesRead);
        if (readBytes <= 0) {
            return LINGLONG_ERR(
              fmt::format("read from sign section error: {}", readBytes == 0 ? "unexpected EOF" : this->errorString().toStdString()));
        }

Comment on lines +179 to +180
auto bytesWritten =
::write(outputFd, buffer.data() + bytesWrittenTotal, bytesRead - bytesWrittenTotal);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The write system call can theoretically return 0 if no bytes were written, which would lead to an infinite loop here. While rare for regular files, it is safer to check for bytesWritten <= 0 to prevent potential hangs.

            auto bytesWritten =
              ::write(outputFd, buffer.data() + bytesWrittenTotal, bytesRead - bytesWrittenTotal);
            if (bytesWritten <= 0) {

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 45.88235% with 46 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...g/src/linglong/package_manager/package_manager.cpp 43.93% 26 Missing and 11 partials ⚠️
.../src/linglong/package_manager/uab_installation.cpp 37.50% 4 Missing and 1 partial ⚠️
libs/linglong/src/linglong/package/uab_file.cpp 62.50% 1 Missing and 2 partials ⚠️
libs/utils/src/linglong/utils/hooks.cpp 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
libs/linglong/src/linglong/package/uab_file.h 100.00% <ø> (ø)
...ong/src/linglong/package_manager/package_manager.h 50.00% <100.00%> (+50.00%) ⬆️
...ng/src/linglong/package_manager/uab_installation.h 50.00% <100.00%> (+50.00%) ⬆️
libs/utils/src/linglong/utils/hooks.h 0.00% <ø> (ø)
libs/utils/src/linglong/utils/hooks.cpp 0.00% <0.00%> (ø)
libs/linglong/src/linglong/package/uab_file.cpp 58.00% <62.50%> (-1.03%) ⬇️
.../src/linglong/package_manager/uab_installation.cpp 13.56% <37.50%> (-0.92%) ⬇️
...g/src/linglong/package_manager/package_manager.cpp 3.72% <43.93%> (+2.57%) ⬆️

... and 97 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dengbo11 dengbo11 marked this pull request as draft April 24, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants