Skip to content

Move target directory handling to driver instead of collection.#49

Open
kreuzberger wants to merge 13 commits into
useblocks:masterfrom
procitec:fix_drivers_directory
Open

Move target directory handling to driver instead of collection.#49
kreuzberger wants to merge 13 commits into
useblocks:masterfrom
procitec:fix_drivers_directory

Conversation

@kreuzberger

Copy link
Copy Markdown
Contributor

In Issue #22 a bug was reported due to directory handling.
This was not so clear to me cause tests were running, but have race conditions in my project due to symlink handling (directory already exists).
So i think investaged and found PR #23, that got stuck due to "responsiblity".
So i tried to get further on it:

@kreuzberger kreuzberger marked this pull request as ready for review April 29, 2026 10:18

@ubmarco ubmarco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

Request changes. The architectural direction (move "make the target dir" from Collection to each Driver) is the right call, but the implementation does not actually fix issue #22 and introduces three latent regressions.

@kreuzberger thanks a lot for the proposal, this is the right thing to do.
Please tell me whether you want to spent the time to fix below blockers.

Blockers

1. The symlink driver — the one named in #22 — is not touched

The PR comments out makedirs(dirname(target)) in collections.py L84–L87 and adds a create_target_dir() helper to the base driver, but drivers/symlink.py L42–L66 is unchanged and never calls the helper. Any user with target: "subdir/my_link" now hits a new FileNotFoundError (parent never created). No symlink test is added.

2. jinja and git drivers are not touched either

Same problem:

Other issues

3. copy_folder is modified but doesn't call create_target_dir

drivers/copy_folder.py L17–L21 — every other modified driver got the helper call. copytree happens to create intermediate dirs, but the inconsistency should be documented or fixed.

4. create_target_dir guard is effectively dead code

drivers/__init__.py L91–L100: by the time the driver sees target, collections.py has resolved it to an absolute path, so any(sep in str(target) for sep in ("/", "\\")) is always true. Replace with if os.path.dirname(target): — handles every case correctly, no special handling needed.

5. Nested try/except in copy_file.py swallows the real error

drivers/copy_file.py L17–L28 — if create_target_dir() raises, the outer handler reports "Problems during copying file" instead of a directory-creation failure. Flatten into a single block or split into two.

6. Misleading comment and leftover dead code in collections.py

L84–L87 — the removed makedirs(dirname(target)) was the existing fix for #22 (commit e8c7229). The "See #22" label suggests the line was the bug, which is the opposite of the truth. Delete the commented lines and reword.

7. Tests silently stop cleaning up

tests/conftest.py L46–L49try/finally now just pass. Either restore shutil.rmtree(sphinx_test_tempdir, True) or drop the try/finally entirely. Also note the typo on L13: tmproot = tmproot = tmp / srcdir.name.

Minimum changes to merge

  1. Add self.create_target_dir(target) to symlink, jinja, git (for symlink, the helper creates only the parent, which is the correct behavior).
  2. Decide copy_folder: add the call or document why it's skipped.
  3. Add a test per affected driver with a nested target (subdir/leaf).
  4. Replace the separator-string check with if os.path.dirname(target):.
  5. Remove the commented-out lines in collections.py; reword the comment.
  6. Flatten the nested try/except in copy_file.py.
  7. Restore or remove the test cleanup try/finally; fix the tmproot typo.

@kreuzberger

kreuzberger commented May 26, 2026

Copy link
Copy Markdown
Contributor Author
  • Thx. 🌴. I work on it later

@kreuzberger kreuzberger marked this pull request as draft June 9, 2026 07:17
@kreuzberger

Copy link
Copy Markdown
Contributor Author

fixed 6: removed commented code, added comment why the target dir is here not created
fixed 7: readed shutil.rmtree (i always enable it to see what happend in the tests) tmproot was already fixed on master
fixed 4: use suggested check
fixed 3: the target directory was not created like for the others cause copytree does this explicitly or throws exception
This is now changed to : create directory always, avoid exception by adding dirs_exist_ok=True.

@kreuzberger kreuzberger force-pushed the fix_drivers_directory branch from d55aaef to 236592d Compare June 12, 2026 12:35
@kreuzberger kreuzberger requested a review from ubmarco June 12, 2026 12:46
@kreuzberger kreuzberger marked this pull request as ready for review June 12, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants