dotter icon indicating copy to clipboard operation
dotter copied to clipboard

[FEATURE] Support binary files

Open nicmr opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. I would like to use dotter to manage binary files that are part of my configuration. However, when deploying these, I get the following error:

[ WARN] File "foo.binary" is not valid UTF-8 - detecting as symlink. Explicitly specify it to silence this message.
[ERROR] Creating symlink "foo.binary" -> "destination" but target isn't a symlink. Skipping.

Describe the solution you'd like dotter supports binary files

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context I'm willing to contribute this myself, I'm going to look at the code but might need some pointers.

nicmr avatar Feb 10 '24 13:02 nicmr

If I understand correctly, dotter currently understands two fundamental file types - symbolic links and utf-8 templates. The current heuristic in crate::filesystem::is_template is to check if the file can be read as a utf-8 string, if it can, it's a template, if it can't, it's a symlink. Later on, when then trying to deploy the file as a symlink in crate::actions::create_symlink, crate::filesystem::FileSystem::compare_symlinks gets called and returns the Error crate::filesystem::FileSystem::SymlinkComparison::TargetNotSymlink. The detection if it really is a symbolic link is performed by crate::filesystem::get_file_state.

nicmr avatar Feb 10 '24 13:02 nicmr

Consequently, if the initial check in crate::filesystem::is_template (which should then probably be renamed) supports reliably determining a file is neither a utf-8 string nor a template, it could handle these independently and not interfere with the handling of the already supported file types. This functionality would not necessarily be limited to binary files, but to any non-utf8 non-symlink files.

nicmr avatar Feb 10 '24 13:02 nicmr

I think the problem is that the error message is not clear enough - the reason for skipping in this case is that the destination file already exists and is something different than Dotter would create (presumably, this is a copy of your binary file)

I'll change the message to target already exists and isn't a symlink. Also, at the end you should see a message explaining that some files were skipped and you should use the --force flag to overwrite.

Let me know if you still have questions :)

SuperCuber avatar Feb 17 '24 15:02 SuperCuber