Fixed RepositoryTool patching of files in uncreated directories
Review Request #10247 — Created Oct. 19, 2018 and submitted
When a RepositoryTool is applying the review's patches to the cloned
repository, it simply writes usingopen(p, 'wb')
. This does not create
directories that the patch implies.This leads to the write failing with:
IOError: [Errno 2] No such file or directory: u'dir/file'
This patch creates directories for each file if the path does not exist
already.
Replciated the error by posting a review for a file in a new directory,
applied patch, and RepositoryTool successfully runs on patched files.
Description | From | Last Updated |
---|---|---|
F401 'os.path' imported but unused |
reviewbot | |
F811 redefinition of unused 'path' from line 8 |
reviewbot | |
E722 do not use bare except' |
reviewbot | |
Blank line between these. |
brennie | |
This doesn't always create directories -- it ensures they exist, so let's call this ensure_directories. |
brennie | |
No space after " |
brennie | |
The path for which directories should be created if they don't exist. |
brennie | |
Blank line between here. |
brennie | |
E722 do not use bare except' |
reviewbot | |
We never want to use bare except. This can catch things that should never be caught, like KeyboardInterrupt or RuntimeError. … |
brennie | |
It seems like we'd probably want to surface the error so that the caller can bail out. |
david | |
Function name would be better as ensure_directories_exist |
ammar |
- Change Summary:
-
Removed unneccessary import
- Commit:
-
c89f67ab14f7da66647f24441492effb299a19cd68b16e6d2c54cd6f564379b0aced9d654dadacd3
-
-
-
This doesn't always create directories -- it ensures they exist, so let's call this
ensure_directories
. -
-
-
-
We never want to use bare
except
. This can catch things that should never be caught, likeKeyboardInterrupt
orRuntimeError
. Instead, this needs to specify the exact exception we expect, which should beOSError
.
- Change Summary:
-
Renamed create_dirs, formatting, and catch OSError instead of bare except.
- Commit:
-
68b16e6d2c54cd6f564379b0aced9d654dadacd3598db0e96d2065bc5f9392d3f8206d1a4de1f0f9
Checks run (2 succeeded)
- Change Summary:
-
Converted to enforcing absolute paths.
- Commit:
-
598db0e96d2065bc5f9392d3f8206d1a4de1f0f933d3cc806cc5c15ecb538468fb93541ca20ecc8d