Skip to content

fix(subcmds/saas): remove timestamped directory in results-dir #2248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

FutureHirai
Copy link
Contributor

@FutureHirai FutureHirai commented Jun 19, 2025

If this Pull Request is work in progress, Add a prefix of “[WIP]” in the title.

What did you implement:

  • WHY

    • In the previous implementation, the results directory was not deleted when an upload failed. This could cause stale files from the failed run to be included in subsequent processes, potentially leading to inaccurate results.
  • WHAT

    • Updated the logic to purge the results directory after each upload attempt, regardless of whether the upload succeeds or fails.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Before

./vuls -v
vuls v0.29.0 build-4e3ee6a
ls
2025-06-19T11-36-43+0900  2025-06-20T14-58-57+0900
./vuls saas
[Jun 20 15:06:29]  INFO [localhost] vuls-v0.29.0-build-4e3ee6a
[Jun 20 15:06:29]  INFO [localhost] Validating config...
[Jun 20 15:06:29]  INFO [localhost] Loaded: /XXX/XXXX/results/2025-06-20T14-58-57+0900
[Jun 20 15:06:35]  INFO [localhost] Uploading... NOTE12794
[Jun 20 15:06:39] ERROR [localhost] Failed to upload. err: Failed to upload data to vuls-results-tmp-prd/1/11118/fa797b8e-2447-ecd4-1e0d-e452ff2472f9.json, err:
    github.com/future-architect/vuls/saas.Writer.Write
        /home/runner/work/futurevuls-backend/futurevuls-backend/scanner-src/saas/saas.go:135
  - operation error S3: PutObject, https response error StatusCode: 0, RequestID: , HostID: , canceled, context deadline exceeded
ls
2025-06-19T11-36-43+0900  2025-06-20T14-58-57+0900

After

./vuls -v
vuls  build-20250619_115602_55cabca
ls
2025-06-19T11-36-43+0900  2025-06-20T14-58-57+0900
./vuls saas
[Jun 20 15:25:42]  INFO [localhost] vuls--build-20250619_115602_55cabca
[Jun 20 15:25:42]  INFO [localhost] Validating config...
[Jun 20 15:25:42]  INFO [localhost] Loaded: /XXX/XXXX/results/2025-06-20T14-58-57+0900
[Jun 20 15:25:47]  INFO [localhost] Uploading... NOTE12794
[Jun 20 15:25:52] ERROR [localhost] Failed to upload. err: Failed to upload data to vuls-results-tmp-prd/1/11118/fa797b8e-2447-ecd4-1e0d-e452ff2472f9.json, err:
    github.com/future-architect/vuls/saas.Writer.Write
        github.com/future-architect/vuls/saas/saas.go:138
  - operation error S3: PutObject, https response error StatusCode: 0, RequestID: , HostID: , canceled, context deadline exceeded
ls
2025-06-19T11-36-43+0900

Checklist:

You don't have to satisfy all of the following.

  • Write tests
  • Write documentation
  • Check that there aren't other open pull requests for the same issue/feature
  • Format your source code by make fmt
  • Pass the test by make test
  • Provide verification config / commands
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES

Reference

@FutureHirai FutureHirai marked this pull request as draft June 19, 2025 07:47
@shino
Copy link
Collaborator

shino commented Jun 19, 2025

Thank you very much for contributing!!

Before detailed review, please let me point two things:

  1. for commit messages, we are using https://www.conventionalcommits.org/ja/v1.0.0/ . For example, fix(subcmds/saas): remove results-dir even when succeeded
  2. in diff, tab characters and spaces are mixed. In Go lang, using only tag characters are standard, I guess.

Thanks again!

@FutureHirai FutureHirai force-pushed the hirai/delete-results-dir branch from 7a91979 to 682f471 Compare June 19, 2025 08:24
@FutureHirai FutureHirai changed the title fix/clean results-dir fix(subcmds/saas): remove results-dir even when succeeded Jun 19, 2025
@FutureHirai FutureHirai force-pushed the hirai/delete-results-dir branch from 23b6e4a to c3e2a94 Compare June 19, 2025 09:13
@shino shino requested a review from Copilot June 19, 2025 09:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures the results directory is purged after every upload attempt (success or failure) by moving the cleanup logic into a deferred function and removing the original post-success cleanup block.

  • Moved os.RemoveAll(dir) into a defer so it always runs on exit
  • Retained the debug flag check to skip removal in debug mode
  • Removed the redundant cleanup block at the end of the function
Comments suppressed due to low confidence (2)

subcmds/saas.go:85

  • [nitpick] The local variable dir is generic and could be renamed to resultsDir (or similar) to clarify its purpose in cleanup.
	defer func() {

subcmds/saas.go:85

  • Consider adding unit tests that simulate both success and failure paths to verify the results directory is removed in all cases.
	defer func() {

@FutureHirai FutureHirai marked this pull request as ready for review June 19, 2025 09:45
@FutureHirai FutureHirai force-pushed the hirai/delete-results-dir branch from c3e2a94 to e68b0f3 Compare June 20, 2025 06:55
@FutureHirai FutureHirai changed the title fix(subcmds/saas): remove results-dir even when succeeded fix(subcmds/saas): remove timestamped directory in results-dir Jun 20, 2025
@FutureHirai FutureHirai requested a review from shino June 20, 2025 07:14
@shino shino requested a review from MaineK00n June 20, 2025 07:32
Copy link
Collaborator

@MaineK00n MaineK00n left a comment

Choose a reason for hiding this comment

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

If an error occurs during the next scan and the timestamped directory is not created, there's a possibility that the previous one might be uploaded instead — is that acceptable?

@FutureHirai
Copy link
Contributor Author

If an error occurs during the next scan and the timestamped directory is not created, there's a possibility that the previous one might be uploaded instead — is that acceptable?

We acknowledge that possibility. We have decided to cover this case with our operational workflow, so this is acceptable.

Copy link
Collaborator

@shino shino left a comment

Choose a reason for hiding this comment

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

Great Job!
Works as advertised!!! 🍻

@shino shino merged commit 3c23560 into future-architect:master Jun 20, 2025
7 checks passed
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