Skip to content

fix: [env] set user`s environment to QApt#334

Merged
max-lvs merged 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:temp1
Jun 17, 2025
Merged

fix: [env] set user`s environment to QApt#334
max-lvs merged 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:temp1

Conversation

@LiHua000

@LiHua000 LiHua000 commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

Log: as title

Bug: https://pms.uniontech.com/bug-view-318565.html

Summary by Sourcery

Set the real user’s environment variable for QApt install and uninstall transactions

Bug Fixes:

  • Propagate SUDO_USER in the transaction environment to preserve the original user context during package installation
  • Propagate SUDO_USER in the transaction environment to preserve the original user context during package uninstallation

@sourcery-ai

sourcery-ai Bot commented Jun 16, 2025

Copy link
Copy Markdown

Reviewer's Guide

Ensure QApt transactions inherit the real user's environment by injecting the SUDO_USER variable before running install and uninstall operations.

Sequence Diagram for SUDO_USER Injection in Package Installation

sequenceDiagram
    participant DLM as DebListModel
    participant ENV as QProcessEnvironment
    participant CTX as "m_currentTransaction (Transaction)"

    DLM->>+DLM: installDebs()
    %% m_currentTransaction is assumed to be set and point to a Transaction object
    DLM->>+ENV: QProcessEnvironment.systemEnvironment()
    ENV-->>-DLM: env
    DLM->>+ENV: env.value("USER")
    ENV-->>-DLM: currentUser
    DLM->>+ENV: env.value("SUDO_USER")
    ENV-->>-DLM: sudoUser
    DLM->>DLM: realUser = determineRealUser(currentUser, sudoUser)
    DLM->>DLM: map = createMapWithSudoUser(realUser)
    DLM->>+CTX: setEnvVariable(map)
    CTX-->>-DLM: 
    DLM->>+CTX: run()
    CTX-->>-DLM: 
    DLM-->>-DLM: %% installDebs ends
Loading

Sequence Diagram for SUDO_USER Injection in Package Uninstallation

sequenceDiagram
    participant DLM as DebListModel
    participant ENV as QProcessEnvironment
    participant TRX as "transsaction (Transaction)"

    DLM->>+DLM: slotUninstallPackage(index)
    %% transsaction = new Transaction()
    %% m_currentTransaction = transsaction
    DLM->>+ENV: QProcessEnvironment.systemEnvironment()
    ENV-->>-DLM: env
    DLM->>+ENV: env.value("USER")
    ENV-->>-DLM: currentUser
    DLM->>+ENV: env.value("SUDO_USER")
    ENV-->>-DLM: sudoUser
    DLM->>DLM: realUser = determineRealUser(currentUser, sudoUser)
    DLM->>DLM: map = createMapWithSudoUser(realUser)
    DLM->>+TRX: setEnvVariable(map)
    TRX-->>-DLM: 
    DLM->>+TRX: run()
    TRX-->>-DLM: 
    DLM-->>-DLM: %% slotUninstallPackage ends
Loading

Class Diagram: DebListModel Update for Environment Variable Handling

classDiagram
    class DebListModel {
        +slotUninstallPackage(const int index): void
        +installDebs(): void
        m_currentTransaction: Transaction
    }
    class Transaction {
        +setEnvVariable(QVariantMap map): void
        +run(): void
    }
    DebListModel ..> Transaction : uses
Loading

File-Level Changes

Change Details Files
Inject real user context into QApt transactions
  • Retrieve system environment via QProcessEnvironment::systemEnvironment
  • Determine realUser using USER and SUDO_USER fallback
  • Insert SUDO_USER into a QVariantMap
  • Call setEnvVariable(map) on the transaction before run
src/deb-installer/model/deblistmodel.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, max-lvs

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

1 similar comment
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, max-lvs

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

@LiHua000

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Jun 17, 2025

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@LiHua000

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Jun 17, 2025

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@max-lvs max-lvs merged commit a2c2fe4 into linuxdeepin:release/eagle Jun 17, 2025
14 of 16 checks passed
LiHua000 added a commit to LiHua000/deepin-deb-installer that referenced this pull request Dec 17, 2025
LiHua000 added a commit to LiHua000/deepin-deb-installer that referenced this pull request Dec 17, 2025
LiHua000 added a commit to LiHua000/deepin-deb-installer that referenced this pull request Dec 18, 2025
LiHua000 added a commit to LiHua000/deepin-deb-installer that referenced this pull request Dec 18, 2025
LiHua000 added a commit to LiHua000/deepin-deb-installer that referenced this pull request Dec 18, 2025
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.

3 participants