Skip to content

Commit 7c39317

Browse files
sfroeberclaude
andcommitted
Review fixes: npmrc portability + symlink.yml directory handling
- dotfiles/npmrc: change hardcoded /home/sfroeber path to ~ (npm expands it; verified prefix still resolves to ~/.npm-global) - ansible/roles/dotfiles/tasks/symlink.yml: replace ansible.builtin.copy (breaks on non-empty directories) and file: state: absent with cp -a + rm -rf shell commands — correctly handles both regular files and non-empty directories when backing up and clearing the dest path Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 8bc4c6f commit 7c39317

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

ansible/roles/dotfiles/tasks/symlink.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# symlink.yml — called with _link_src and _link_dest variables.
33
#
44
# Logic:
5-
# 1. If dest is a regular file (not a symlink) → back it up, then remove it.
6-
# 2. If dest is already a symlink to the right target → no-op.
7-
# 3. If dest is a symlink to somewhere else → re-point it.
5+
# 1. If dest is already a symlink to the right target → no-op.
6+
# 2. If dest is a symlink to somewhere else → re-point it.
7+
# 3. If dest is a regular file or non-empty directory → back it up with
8+
# cp -a (handles both), then remove it with rm -rf.
89
# 4. Create the symlink.
910

1011
- name: "Stat {{ _link_dest }}"
@@ -13,23 +14,28 @@
1314
follow: false
1415
register: _sym_stat
1516

16-
- name: "Back up {{ _link_dest }} if it is a regular file"
17-
ansible.builtin.copy:
18-
src: "{{ _link_dest }}"
19-
dest: "{{ dotfiles_backup_dir }}/{{ _link_dest | basename }}.bak"
20-
remote_src: true
21-
mode: preserve
17+
- name: "Back up {{ _link_dest }} (file or directory) before replacing"
18+
ansible.builtin.command:
19+
argv:
20+
- cp
21+
- -a
22+
- "{{ _link_dest }}"
23+
- "{{ dotfiles_backup_dir }}/{{ _link_dest | basename }}.bak"
2224
when:
2325
- _sym_stat.stat.exists
2426
- not _sym_stat.stat.islnk
27+
changed_when: true
2528

2629
- name: "Remove {{ _link_dest }} before symlinking"
27-
ansible.builtin.file:
28-
path: "{{ _link_dest }}"
29-
state: absent
30+
ansible.builtin.command:
31+
argv:
32+
- rm
33+
- -rf
34+
- "{{ _link_dest }}"
3035
when:
3136
- _sym_stat.stat.exists
3237
- not (_sym_stat.stat.islnk and _sym_stat.stat.lnk_source == _link_src)
38+
changed_when: true
3339

3440
- name: "Create symlink {{ _link_dest }} → {{ _link_src }}"
3541
ansible.builtin.file:

dotfiles/npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
prefix=/home/sfroeber/.npm-global
1+
prefix=~/.npm-global

0 commit comments

Comments
 (0)