Skip to content

Commit

Permalink
Workaround host-pkg issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Dec 21, 2023
1 parent b5bf976 commit a343d6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/cache.toit
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ class Cache:
// TODO(florian): add a `delete` method.
ensure-cache-directory_:
directory.mkdir --recursive path
if not file.is-directory path:
// TODO(florian): remove this work-around.
// The current host package (1.11.0) assumes that the path uses '/' as separators.
slash-path := fs.to-slash path
directory.mkdir --recursive slash-path

/**
Escapes the given $path so it's valid.
Expand Down Expand Up @@ -381,6 +385,9 @@ class FileStore_ implements FileStore:
block.call tmp-path
key-path := cache_.key-path_ key
key-dir := fs.dirname key-path
// TODO(florian): remove this work-around.
// The current host package (1.11.0) assumes that the path uses '/' as separators.
key-dir = fs.to-slash key-dir
directory.mkdir --recursive key-dir
atomic-move-file_ tmp-path key-path

Expand Down Expand Up @@ -444,6 +451,9 @@ class DirectoryStore_ implements DirectoryStore:
block.call tmp-dir
key-path := cache_.key-path_ key
key-dir := fs.dirname key-path
// TODO(florian): remove this work-around.
// The current host package (1.11.0) assumes that the path uses '/' as separators.
key-dir = fs.to-slash key-dir
directory.mkdir --recursive key-dir
atomic-move-directory_ tmp-dir key-path

Expand Down
6 changes: 5 additions & 1 deletion src/config.toit
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ class Config:
Writes the configuration map $data to the given $path.
*/
write-config-file_ path/string data/Map:
directory.mkdir --recursive (fs.dirname path)
// TODO(florian): remove this workaround.
// The current host package assumes that the path uses '/' as separators.
dir-path := fs.dirname path
dir-path = fs.to-slash dir-path
directory.mkdir --recursive dir-path

content := json.encode data
stream := file.Stream.for-write path
Expand Down
10 changes: 7 additions & 3 deletions src/utils_.toit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by an MIT-style license that can be
// found in the package's LICENSE file.
import fs
import host.directory
import host.file
import host.os
Expand Down Expand Up @@ -47,6 +48,10 @@ 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:
// We convert to '/' as separators:
// 1. the current host package (1.11.0) expects '/' as separators for mkdir --recursive.
// 2. Tar can't handle backslashes as separators.
target = fs.to-slash target
directory.mkdir --recursive target
with-tmp-directory: | tmp-dir |
// We are using `tar` so we keep the permissions and symlinks.
Expand All @@ -56,9 +61,8 @@ copy-directory --source/string --target/string:
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 "\\" "/"
source = fs.to-slash source
tmp-tar = fs.to-slash tmp-tar
extra-args = ["--force-local"]

// We are using an intermediate file.
Expand Down

0 comments on commit a343d6b

Please sign in to comment.