-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add copy target type #79
Conversation
Misclick |
This looks pretty good! I'll go through it on my pc when I get to it |
Other than my one comment this looks very good. I commend you for even adding tests to it :D
Two more things before this can be released:
|
I tried doing this, but this resulted in a lot of boilerplate in the comparison functions ( I noticed that there are some instances where we read the file contents for a second time using
Seems like Github doesn't let me do this from a PR. I think you'll have to do it on your side. |
Just realized that there's a bug with updating copy targets. We can only detect that there is a difference between the source and target, but we cannot detect which one was modified. So, modifying the source and then trying to update results in dotter telling us that the target has been modified. Template targets compare the cached file and the target file, and because we can assume that the cached file is unmodified (since users shouldn't be modifying the cache directly), the target file must have been modified if there is a change detected. We can't do the same for copy targets because we don't copy the file to the cache. I think there are several approaches we can take from here:
The second method is probably the easiest to implement, but making an additional copy isn't very efficient storage-wise. The first method may upset users who accidentally modified the target file instead of the source file. I'm leaning towards the third method as it would eliminate the inefficiency of comparing files byte by byte. We can apply this to |
Sorry for the late reply, for some reason I wasn't subscribed to the PR so I didn't see your comment. Regarding your solution 3, I think this is an interesting idea, although it seems like there's some nuance to how I was thinking instead of storing the timestamp as the content of the file you could have an empty file that is touched right after the target is updated - this way you can just compare the timestamps of the two files to see which one was modified last (should be cache). I don't see a reason why this can't be extended to templates as well. The big issue I see with this is we now need to handle migrating between someone using the old cache format and the new one. |
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 don't think this change is neccesary - if the hook isn't a template then it will just make a file that is the same as the original...
IMO this complicates the function significantly (adds a Filesystem for example) for a small performance boost in case the hook isn't a template (which it probably is for most use cases)
No worries! It's been a busy past few weeks for me so I wouldn't have been able to work on this anyway.
Yeah, it's certainly a nuance, but I assume time drift is a very rare occurrence. There's also the fact that users can modify the timestamps. But since
Ah, I was actually thinking of serializing the timestamps into |
Now that I think about it, the Err case is the one that means that the file was modified. So time drift is probably undetectable... Meh, worst-case scenario the user will force deploy without understanding why.
This is an idea I haven't considered. It does seem pretty good, and it means we can remove cache folder altogether. (if serde supports SystemTime of course) It's looking like the scope of this change is pretty big though - maybe enough to have its own "Remove cache folder" pull request... What do you think? |
I added this change because users would get the |
Yeah, I figured I missed something like that. Good edge case catch :D |
Just checked, and seems like it does!
Yeah, I think it's big enough to have its own PR. We could temporarily put this PR on hold, and merge the "remove cache folder" PR first. And then finally rebase this PR on top. That way, no needless work would need to be done. |
Sounds good. |
@SuperCuber @PlayerNameHere Any update about this PR? |
Seems like we both lost interest/need in this. |
Yes this feature is very important for me. You could build some os part(archlinux) with the sudo cp option |
You're welcome to open another PR. |
Any updates on this? A copy feature would be really appreciated. |
This is not being worked on. PRs are welcome :) |
Hey, really sorry for ghosting this. I had been really busy with life and did not have the time to work on this PR. Unfortunately, I don't plan to continue working on this as I don't really have a need for it anymore. That said, if anyone would like to work on this, please feel free to use the code in this PR. |
Closes #77.
Implements a new
copy
target type.This is a much bigger change than I had expected, so there may be bugs and things I've missed. I've marked the PR as a draft for now, as there are still some things that I think should be discussed:
std::fs::read_to_string()
. So, non-UTF-8 files end up asFileState(File(None))
. We could read files into a bytes vector instead usingstd::fs::read()
, but this would require changes in a lot of places.symbolic
andautomatic
targets fallback totemplate
. I think it would be better to fallback tocopy
instead, though this could potentially be breaking. Forautomatic
targets, we can usefs.is_template()
to determine whether to usecopy
ortemplate
; whereas forsymbolic
, we would just default tocopy
.copy
in the error for non-UTF-8 templates, as you suggested, would be nice, but I wasn't sure how to fit this in the code.On a side note, there are a lot of clippy warnings about references. Were those left intentionally?