This repository was archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Add our own copy.exe binary so that we can copy without cmd.exe #65
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"os" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
args := os.Args[1:] | ||
|
||
// Make sure there are only two arguments | ||
if len(args) != 2 { | ||
log.Fatalf("%s <source> <destination>", os.Args[0]) | ||
} | ||
|
||
source_path := args[0] | ||
destination_path := args[1] | ||
|
||
// Make sure the source file exists | ||
source_file, err := os.Open(source_path) | ||
exit_if_error(err) | ||
defer source_file.Close() | ||
|
||
// Make sure we can create the destination file | ||
destination_file, err := os.Create(destination_path) | ||
exit_if_error(err) | ||
defer destination_file.Close() | ||
|
||
// Copy | ||
_, err = io.Copy(destination_file, source_file) | ||
exit_if_error(err) | ||
|
||
// Report | ||
fmt.Printf("Copied %s to %s\n", source_path, destination_path) | ||
} | ||
|
||
func exit_if_error(err error) { | ||
if err != nil { | ||
log.Fatal("ERROR:", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason for using log.* functions for errors, instead of just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you're creating an empty version of the dest. file in order to check if you can access that path? is there a cleaner way to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It creates to get a file handle, so that
io.Copy()
can use itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fair enough