mxcl / swift-sh

Easily script with third-party Swift dependencies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

caching problem if script by same name is in two locations in the file system

haikusw opened this issue · comments

commented

Just had a similar issue to #64 just come up:

Simple case:

  1. create two folders: "test", "test2"
  2. in folder "test", create a file "test.swift" with the following contents:
#!/usr/bin/swift sh
print("hello from 'test' folder")
  1. copy "test.swift" into the "test2" folder.
  2. edit "test2/test.swift" to change the string "hello from 'test' folder" to "hello from 'test2' folder" and save the file.
  3. in terminal, cd to "test" folder and execute the test.swift file via ./test.swift
    -> builds and runs, prints:

    hello from 'test' folder

  4. still in the terminal, cd into "test2" folder and execute the test.swift file via .test.swift
    -> ISSUE: you get the same string printed and test.swift is NOT built:

    hello from 'test' folder
    Should build test.swift and print:
    hello from 'test2' folder

Seems like we need either a disambiguation strategy for cache folders that took into account location in the file system, or perhaps a step during swift-sh execution that validates that the Main.swift alias points to the actual file being executed and not some other copy of it somewhere in the file system.

commented

So I pulled the PR because it wasn't a solution in every case (really long path names that had the same last 128 base64'd characters would still conflict.

The better solution would be to use Swift+md5.swift from the xcodeproj package and do the md5 hash. However that package is currently macOS only. So I had to move that source file into the main project. Test suite all passes when run locally. Probably needs to be tested on Linux and iOS now. Making a PR to let it run all automated tests here.

commented

I believe the PR is ready to merge. There was a failing test but it's not in anything I changed and not sure what it's there for. All tests pass in 10.15.2 and Xcode 11.3 on my machine and it passed all but one macOS instance (seems odd).

Test Suite 'All tests' passed at 2019-12-25 01:59:31.644.
Executed 55 tests, with 0 failures (0 unexpected) in 92.938 (92.943) seconds

commented

If you want to first just merge in the failing test to demonstrate the issue, this commit for the test stands alone:

haikusw@15ee4f9