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

Don't use 'tar' to copy directories. #58

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/package.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sdk: ^2.0.0-alpha.120
sdk: ^2.0.0-alpha.128
prefixes:
cli: ..
host: pkg-host
Expand All @@ -11,12 +11,12 @@ packages:
pkg-fs:
url: github.com/toitlang/pkg-fs
name: fs
version: 2.1.0
hash: ac3933367912563055ceea4188adcead3428103c
version: 2.2.0
hash: 863280c5c62ac259d16d0d3b24df21209b461b14
prefixes:
host: pkg-host
pkg-host:
url: github.com/toitlang/pkg-host
name: host
version: 1.12.0
hash: fe5e10c56abc3fca1ef9bcba415e77fd59183cab
version: 1.14.1
hash: da453fb59f7ef3d37f39e4b438495f7c16614733
2 changes: 1 addition & 1 deletion examples/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ dependencies:
path: ..
host:
url: github.com/toitlang/pkg-host
version: ^1.12.0
version: ^1.14.1
10 changes: 5 additions & 5 deletions package.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
sdk: ^2.0.0-alpha.120
sdk: ^2.0.0-alpha.128
prefixes:
fs: pkg-fs
host: pkg-host
packages:
pkg-fs:
url: github.com/toitlang/pkg-fs
name: fs
version: 2.1.0
hash: ac3933367912563055ceea4188adcead3428103c
version: 2.2.0
hash: 863280c5c62ac259d16d0d3b24df21209b461b14
prefixes:
host: pkg-host
pkg-host:
url: github.com/toitlang/pkg-host
name: host
version: 1.12.0
hash: fe5e10c56abc3fca1ef9bcba415e77fd59183cab
version: 1.14.1
hash: da453fb59f7ef3d37f39e4b438495f7c16614733
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:
dependencies:
fs:
url: github.com/toitlang/pkg-fs
version: ^2.1.0
version: ^2.2.0
host:
url: github.com/toitlang/pkg-host
version: ^1.12.0
version: ^1.14.1
38 changes: 1 addition & 37 deletions src/utils_.toit
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import host.directory
import host.file
import host.os
import host.pipe
import system

/**
Expand All @@ -23,46 +22,11 @@ with-tmp-directory [block]:
finally:
directory.rmdir --recursive tmpdir

tool-path_ tool/string -> string:
if system.platform != system.PLATFORM-WINDOWS: return tool
// On Windows, we use the <tool>.exe that comes with Git for Windows.

// TODO(florian): depending on environment variables is brittle.
// We should use `SearchPath` (to find `git.exe` in the PATH), or
// 'SHGetSpecialFolderPath' (to find the default 'Program Files' folder).
program-files-path := os.env.get "ProgramFiles"
if not program-files-path:
// This is brittle, as Windows localizes the name of the folder.
program-files-path = "C:/Program Files"
result := "$program-files-path/Git/usr/bin/$(tool).exe"
if not file.is-file result:
throw "Could not find $result. Please install Git for Windows"
return result

/**
Copies the $source directory into the $target directory.

If the $target directory does not exist, it is created.
*/
// TODO(florian): this should not use 'tar'. Once we have support for
// symlinks this function should be rewritten.
copy-directory --source/string --target/string:
directory.mkdir --recursive target
with-tmp-directory: | tmp-dir |
// We are using `tar` so we keep the permissions and symlinks.
tar := tool-path_ "tar"

tmp-tar := "$tmp-dir/tmp.tar"
extra-args := []
if system.platform == system.PLATFORM-WINDOWS:
// Tar can't handle backslashes as separators.
source = source.replace --all "\\" "/"
target = target.replace --all "\\" "/"
tmp-tar = tmp-tar.replace --all "\\" "/"
extra-args = ["--force-local"]

// We are using an intermediate file.
// Using pipes was too slow on Windows.
// See https://github.com/toitlang/toit/issues/1568.
pipe.backticks [tar, "c", "-f", tmp-tar, "-C", source, "."] + extra-args
pipe.backticks [tar, "x", "-f", tmp-tar, "-C", target] + extra-args
file.copy --recursive --source=source --target=target
10 changes: 5 additions & 5 deletions tests/package.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sdk: ^2.0.0-alpha.120
sdk: ^2.0.0-alpha.128
prefixes:
cli: ..
host: pkg-host
Expand All @@ -11,12 +11,12 @@ packages:
pkg-fs:
url: github.com/toitlang/pkg-fs
name: fs
version: 2.1.0
hash: ac3933367912563055ceea4188adcead3428103c
version: 2.2.0
hash: 863280c5c62ac259d16d0d3b24df21209b461b14
prefixes:
host: pkg-host
pkg-host:
url: github.com/toitlang/pkg-host
name: host
version: 1.12.0
hash: fe5e10c56abc3fca1ef9bcba415e77fd59183cab
version: 1.14.1
hash: da453fb59f7ef3d37f39e4b438495f7c16614733
2 changes: 1 addition & 1 deletion tests/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ dependencies:
path: ..
host:
url: github.com/toitlang/pkg-host
version: ^1.12.0
version: ^1.14.1