Shemnei / punktf

⚡ A cross-platform multi-target dotfiles manager
https://shemnei.github.io/punktf/
Other
82 stars 6 forks source link

[BUG] - whole path name is included when specifying a file with a target #158

Open ekarious opened 3 months ago

ekarious commented 3 months ago

Describe the bug Bug to the path of uploaded files

To Reproduce When You have a structure like this:

dotfiles
   windows
      alacritty.toml
profiles
   windows.yaml

and windows.yaml file like this:

target: "C:\\Users\\Yann\\Desktop\\test_dotfiles"

dotfiles:
  - path: windows/alacritty.toml
    target:
      path: "C:\\Users\\Yann\\Desktop\\test_dotfiles\\alacritty.toml"
    template: false

The problem is the file is sent to this path:

C:\Users\Yann\Desktop\test_dotfiles\windows\alacritty.toml

The windows in the path should not be included.

Expected behavior This should be the correct path:

C:\Users\Yann\Desktop\test_dotfiles\alacritty.toml

Desktop (please complete the following information):

Additional Infos I have set the Env Variable: PUNKTF_SOURCE = C:\Users\Yann\.dotfiles

ekarious commented 3 months ago

If I add a rename to the dotfiles element, I can remove the windows from the path. But it should not be necessary when the target path is specified.

Shemnei commented 2 months ago

Hey @ekarious thanks for reporting this and sorry for the very late response. What you describe, is indeed a bug and the rename workaround should not be necessary. I will take a look if i can reproduce this and then fix it.

Shemnei commented 2 months ago

Had a quick look and found a few issues:

Unused field

In your example you have the field target.path set for a dotfile. This field does not exist on a dotfile, the field meant to be used for this is overwrite_target.

Currently punktf will only return an error about unused/unknown variables if they are on the profile level, all "sublevel" (e.g. dotfiles) are not checked.

This is a bug and i will fix it.

Rename

I don't if your example is representative of your actual profile, but if it is, i would suggest to actually use rename:

target: "C:\\Users\\Yann\\Desktop\\test_dotfiles"

dotfiles:
  - path: windows/alacritty.toml
    rename: "alacritty.toml"
    template: false

This should deploy the file to the default profile.target with the name/relative path alacritty.toml.

Overwrite Target

While looking through the code for the path resolution, i also noticed that even if you would have used overwrite_target, it would not have worked. I think you are correct with our assumption of how this value should work and will adjust it in this way, also i no longer like the original name of overwrite_target and will rename it to target instead (will probably keep the old name around for backwards compatibility).

After i implement all these changes your given example should almost work in the way you described/expected it to work.

target: "C:\\Users\\Yann\\Desktop\\test_dotfiles"

dotfiles:
  - path: windows/alacritty.toml
    target: "C:\\Users\\Yann\\Desktop\\test_dotfiles\\alacritty.toml"
    template: false

Thank you very much for the feedback/report 😄

Shemnei commented 2 months ago

I will keep you updated but it might take a few days for me to implement all of that

ekarious commented 2 months ago

Thank you very much for the response. Glad I could help you enhanced it :)