Skip to content

feat(app): delete parent dir after uninstall app#8350

Merged
wanghe-fit2cloud merged 1 commit intodev-v2from
pr@dev-v2@common
Apr 8, 2025
Merged

feat(app): delete parent dir after uninstall app#8350
wanghe-fit2cloud merged 1 commit intodev-v2from
pr@dev-v2@common

Conversation

@zhengkunwang223
Copy link
Copy Markdown
Member

No description provided.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 8, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 8, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from zhengkunwang223. For more information see the Kubernetes Code Review Process.

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

Comment thread agent/app/task/task.go

func NewTask(name, operate, taskScope, taskID string, resourceID uint) (*Task, error) {
if taskID == "" {
taskID = uuid.New().String()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. The function CheckResourceTaskIsExecuting is declared but not used anywhere in the provided code.
  2. The parameter scope is defined twice with different types (string and repo.ResourceScope). This may cause confusion unless they are meant to be of the same type.

Overall, there isn't significant irregularity or potential issue detected in this update snippet from April 2023.

}
tx.Commit()
return nil
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The added code to handle empty parent directories is beneficial for maintaining directory structure consistency. Here’s a brief summary of the changes:

  1. import "path/filepath" is added at the top of the file to use functions from this package.

  2. Inside the deleteAppInstall function:

    • If an application installation entry exists, it iterates through each instance associated with the app ID.
    • For each instance, it deletes files and folders using _ = op.DeleteDir(...).
  3. After deleting the child directory (appDir) within its parent, additional logic is implemented for handling an empty parent directory conditionally:

    • The full path of the parent directory is obtained using filepath.Dir(appDir).
    • An attempt is made to read all entries (files/folders) in that parent directory via os.ReadDir(parentDir).
    • If the parent directory has no entries left (i.e., there are no remaining files/folders), it attempts to delete it again.

Optimization Suggestions:

  • Consistent Error Handling: Ensure consistent error handling across the codebase to maintain reliability and prevent silent failures due to missing imports or unexpected errors.

  • Avoid Duplicated Code: Review if these checks can be reused elsewhere in the codebase to avoid duplication, potentially improving scalability and maintenance efficiency.

  • Testing: Consider adding comprehensive tests to cover scenarios where parent directories might remain non-empty after deletions, which could indicate other underlying issues in the system.

By incorporating these optimizations, the overall functionality remains robust while also making the code more reusable and maintainable over time.

}
});
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code seems mostly correct, but here are a few improvements and suggestions:

  1. Exception Catches: The catch blocks can be merged to reduce redundancy. If only one error handling is needed after executing the promise chain (InstallPHPExtension(req)), then remove the second catch block.

  2. Variable Naming Consistency: Consider using PascalCase for variable names to improve readability, especially if they represent classes or objects.

  3. Promise Chaining Optimization: Ensure that each step of the promise chain is independent and does not rely on the outcome of another step. This helps in maintaining clean and modular code.

Here's an optimized version of the function:

const installExtension = async (row: Runtime.SupportExtension) => {
    try {
        await InstallPHPExtension(row.req); // Use PascalCase for req
        taskLogRef.value.openWithTaskID(row.req.taskID);
    } catch (error) {
        console.error('Error installing extension:', error);
    } finally {
        loading.value = false;
    }
};

Remember to adjust any other variables or functions in your project to maintain consistency with these guidelines.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 8, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@wanghe-fit2cloud wanghe-fit2cloud merged commit d67dfe2 into dev-v2 Apr 8, 2025
4 of 6 checks passed
@wanghe-fit2cloud wanghe-fit2cloud deleted the pr@dev-v2@common branch April 8, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants