-
Notifications
You must be signed in to change notification settings - Fork 251
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
feat(up): add --allow-transient-write #618
Conversation
crates/loader/src/local/assets.rs
Outdated
let perms = tokio::fs::metadata(&to).await?.permissions(); | ||
// perms.set_readonly(true); | ||
tokio::fs::set_permissions(&to, perms).await?; | ||
let mut perms = tokio::fs::metadata(&to).await?.permissions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The let mut perms = ...; perms.set_readonly(...); set_permissions(..., perms).await.with_context(...)
sequence seems to happen in quite a few places. Could we create a utility function (e.g. set_writeable
or allow_write
) to tidy and reveal intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I add change_file_permission
function for it. Thank you.
a4d3984
to
ff3106a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me - thanks! Just two comments - the doc string is must-fix, but the comment one is just nice to have.
crates/loader/src/bindle/assets.rs
Outdated
return Ok(()); | ||
} | ||
Ok(false) => { | ||
// if destination file is read-only, set it to writable first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment sent me in the wrong direction a bit (I thought there was a bug where you forgot to consult allow_transient_writes
), partly because check_existing_file
is already confusing! I think this branch is "file exists but digest doesn't match so it's like corrupted. In which case this is "set it writeable because we need to overwrite it" I think? Sort of a "comment says what the code is doing but needs to say why instead" issue if that makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I change it to file exists but digest doesn't match, set it to writable first for further writing
. Do you think it's more clear? Thank you.
src/commands/up.rs
Outdated
@@ -81,6 +81,10 @@ pub struct UpCommand { | |||
#[clap(long = "temp")] | |||
pub tmp: Option<PathBuf>, | |||
|
|||
/// Temporary directory for the static assets of the components. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc string doesn't look right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it. Thank you.
ff3106a
to
2dc76b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me - thanks for the tidying! There is a doc string that I missed before (sorry) that I think is wrong but it's not user-facing so it's not a blocker - but if you have time to fix it then that would be awesome. Otherwise happy to merge and fix it up later.
crates/loader/src/assets.rs
Outdated
@@ -90,6 +90,19 @@ pub fn file_sha256_digest_string(path: impl AsRef<Path>) -> std::io::Result<Stri | |||
Ok(digest_string) | |||
} | |||
|
|||
/// Return an error if a path is not under a given directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for missing this before but I think this doc string is incorrect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @itowlson, no worries, it's my fault that I didn't check it carefully. Thanks for catching it!
Signed-off-by: Frank Yang <yangpoan@gmail.com>
2dc76b2
to
e696996
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - thanks and sorry for the multiple go-arounds!
resolve #605
Test cases
Please run the following script at the end of each case.
Local
Setup
Case 1: new file can be set to read-only
Should show Not Writable.
Case 2: same temporary folder can be changed to writable
Follow case 1. Should show Writable.
../../../target/debug/spin up --temp $TEMP --allow-transient-write
Case 3: new file can be set to writable
Should show Writable.
Bindle
Setup
Case 4: new file can be set to read-only
Should show Not Writable.
Case 5: same temporary folder content can be updated
Stop the bindle-server and start a new bindle-server with a new temporary folder.
Update content in
spin/tests/http/simple-spin-rust/assets/test.txt
. Run spin up again. The file in the temporary folder should be updated and it is still Not Writable after the update.Case 6: same temporary folder can be changed to writable
Follow case 5. Should show Writable.
./target/debug/spin up --temp $TEMP --bindle spin-hello-world/1.0.0 --allow-transient-write
Case 7: new file can be set to writable
Should show Not Writable.