-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back support for file:// sources (#86)
Solbuild 1.5.3.0 replace the way files are downloaded. The feature to download files using `file://` sources was lost. Restore the functionality to set sources using `file://` by copying the file when encountered. Resolves #38.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,37 @@ | ||
package source | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/url" | ||
"os" | ||
) | ||
|
||
const ( | ||
dstFileMode = 0o644 | ||
dstFileFlags = os.O_CREATE | os.O_TRUNC | os.O_WRONLY | ||
) | ||
|
||
// IsFileURI returns true if the given URI is a file:// URI. | ||
func IsFileURI(uri *url.URL) bool { | ||
return uri.Scheme == "file" | ||
} | ||
|
||
// CopyFile copies a file. | ||
func CopyFile(src, dst string) error { | ||
srcFile, err := os.Open(src) | ||
if err != nil { | ||
return fmt.Errorf("unable to open source file: %w", err) | ||
} | ||
|
||
dstFile, err := os.OpenFile(dst, dstFileFlags, dstFileMode) | ||
if err != nil { | ||
return fmt.Errorf("unable to open destination file: %w", err) | ||
} | ||
|
||
if _, err = io.Copy(dstFile, srcFile); err != nil { | ||
return fmt.Errorf("unable to copy file contents: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains 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