#1106412 stow: restow sometimes fails with empty directories

#1106412#5
Date:
2025-05-24 14:50:47 UTC
From:
To:
  Hi,
  In some situation, "stow -R" fails when there are empty directories.
Here is an example:

$ tree .
.
├── dest
└── from
    ├── A
    │   ├── d1
    │   │   └── fa
    │   └── d2
    │       └── fa2
    ├── B
    │   └── d1
    │       └── fb
    └── C
        └── d1

10 directories, 3 files
$ stow -v  --dir from --target dest -R A B C
LINK: d1 => ../from/A/d1
LINK: d2 => ../from/A/d2
UNLINK: d1 (reverts previous action)
MKDIR: d1
LINK: d1/fa => ../../from/A/d1/fa
LINK: d1/fb => ../../from/B/d1/fb
$ tree .
.
├── dest
│   ├── d1
│   │   ├── fa -> ../../from/A/d1/fa
│   │   └── fb -> ../../from/B/d1/fb
│   └── d2 -> ../from/A/d2
└── from
    ├── A
    │   ├── d1
    │   │   └── fa
    │   └── d2
    │       └── fa2
    ├── B
    │   └── d1
    │       └── fb
    └── C
        └── d1

12 directories, 5 files
$ stow -v  --dir from --target dest -R A B C
UNLINK: d1/fa
UNLINK: d1/fb
RMDIR d1
LINK: d1 => ../from/B/d1
UNLINK: d2
UNLINK: d1 (reverts previous action)
stow: ERROR: unstow_contents() called with invalid target: d1

When initial stow is done (or restow without a previous stow as shown here), it works.
But the last case, with a real restow (but no changes in sources), leads to an error.
If I put a file in from/C/d1, it works (not shown here).
If I change the package order, it might work!

$ stow -v  --dir from --target dest -R A C B
UNLINK: d1/fa
UNLINK: d1/fb
RMDIR d1
LINK: d1 => ../from/B/d1
UNLINK: d2
UNLINK: d1 (reverts previous action)
LINK: d1 => ../from/A/d1
LINK: d2 => ../from/A/d2 (reverts previous action)
UNLINK: d1 (reverts previous action)
MKDIR: d1 (reverts previous action)
LINK: d1/fa => ../../from/A/d1/fa (reverts previous action)
LINK: d1/fb => ../../from/B/d1/fb (reverts previous action)

[B and C packages are swaped on the command line, no other changes]

  Regards,
    Vincent