jordwalke / esy-issues

Easy ISSUES
MIT License
49 stars 5 forks source link

[MID PRI] Relocate artifacts from cache to local project. #78

Open jordwalke opened 7 years ago

jordwalke commented 7 years ago

Now that @IwanKaramazow has an example of a fast C string replacement implementation, we can more quickly relocate artifacts that could include paths in them. Right now we use python, and that has some issues:

Currently, we only rewrite artifacts to achieve atomicity - moving from a holding cell where we perform the build _insttmp to _install- in order to make sure that binaries don't include paths from the global cache's _insttmp directory, to the global cache's _install directory (but only on success).

But we can also move artifacts from the global cache's _install directory to the local project's _install directory! This has many benefits:

  1. People can completely purge their cache without having to orphan global installs.
  2. It will enable support for BuckleScript, which expects its artifacts to be in a very specific location, and can not yet be configured to look in another location.
IwanKaramazow commented 7 years ago

Just posting some insights from @andreypopp :

"But we can also move artifacts from the global cache's _install directory 
to the local project's _install directory!" 

> That may be fragile. You need to account for null byte.
> Currently the only replace happens from _inttmp to _install (same length path). 
    Not sure how this going to work with different length path 
    (you don't want to corrupt binaries!)(edited)
> If len(src) > len(repl) you can just leave padding but what if it's the otherwise?
jordwalke commented 7 years ago

I was thinking that we could ensure that the store was something like:

~/.esy/store/_install__________________________really_long -> ~/.esy/store/_install
~/.esy/store/_insttmp__________________________really_long -> ~/.esy/store/_instmp
~/.esy/store/_install
~/.esy/store/_insttmp

Where we always build into the really long directories, and only provide short versions as symlinks for convenience. Then we know that we can relocate to any destination, but ensuring that we create the padded length at the destination site. For example, perhaps you might end up relocating artifacts from the cache to:

└── node_modules/
    └── myDep/
        ├── _install/ -> ./_install_____just_enough_padding___/
        └── _install_____just_enough_padding___/
            └── bin/app.exe

Also, we only even need to pad like this when we detect that a relocation was even necessary. If no string replace occurred, then no funny directory padding needs to take place.

jordwalke commented 7 years ago

Another way to smooth this process out, is if you detect up front whether or not the paths will provide enough padding, and then do not use the cache at all when:

  1. The paths do not allow relocating due to length.
  2. And some artifact needs to be relocated as part of the build process.

I imagine we can incrementally work our way to the ideal workflow, even if as a first step we just refuse to build or something.

jordwalke commented 7 years ago

Clarifying some requirements:

jordwalke commented 7 years ago

Downgrading to mid-pri, not because it's not important but because:

Still important, but just slightly behind all the other stuff marked HIGH pri.