Skip to content
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

Fixed an error when using the command to download src #2940

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

waitstory
Copy link

issue: #2938

Description

Fixed an error when using the command to download src

Which issue(s) this PR fixes:

Fixes #2938

Testing

Checklist:

  • I ran tests as well as code linting locally to verify my changes.
  • I have done manual verification of my changes, changes working as expected.

issue: fission#2938

Signed-off-by: waitstory <waitstory@163.com>
Copy link

sweep-ai bot commented May 16, 2024

Sweep: PR Review

Sweep has finished reviewing your pull request.

pkg/fission-cli/cmd/package/util/util.go

The changes import the os/exec package and replace the os.Rename function with the Unix mv command executed via exec.Command.

Potential Issues

  • Replacing os.Rename with exec.Command("mv", path, fileName) introduces a dependency on the Unix mv command, which may not be available or behave consistently across different environments.
  • cmd := exec.Command("mv", path, fileName)
    _, err = cmd.Output()


@sanketsudake
Copy link
Member

Just following golang/go#41487 so see if there is better way to handle this issue.

@waitstory
Copy link
Author

Just following golang/go#41487 so see if there is better way to handle this issue.就按照 golang/go#41487 看看是否有更好的方法来处理这个问题。

There seems to be no direct solution to the problem

@@ -217,7 +218,8 @@ func WriteArchiveToFile(fileName string, reader io.Reader) error {
return err
Copy link
Member

Choose a reason for hiding this comment

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

Probably we can just make this function simple without using rename or mv and getting rid of the temp file.

func WriteArchiveToFile(fileName string, reader io.Reader) error {
	// Create the target file directly
	file, err := os.Create(fileName)
	if err != nil {
		return err
	}
	defer file.Close()

	// Copy data from the reader to the target file
	_, err = io.Copy(file, reader)
	if err != nil {
		return err
	}

	// Change the permissions of the target file
	err = os.Chmod(fileName, 0644)
	if err != nil {
		return err
	}

	return nil
}

Copy link
Author

Choose a reason for hiding this comment

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

Seems like a good idea

@sanketsudake
Copy link
Member

@waitstory Would you like to make the above change or should I raise a separate PR?

@waitstory
Copy link
Author

Let me make the change and submit it

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.

Download source code to file error when using fission command
2 participants