-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise when trying to acquire in R/O or missing folder (#96)
- Loading branch information
1 parent
684d69d
commit c9b6d90
Showing
7 changed files
with
122 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ testing = | |
coverage>=4 | ||
pytest>=4 | ||
pytest-cov | ||
pytest-timeout>=1.4.2 | ||
|
||
[bdist_wheel] | ||
universal = true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import stat | ||
import sys | ||
|
||
PermissionError = PermissionError if sys.version_info[0] == 3 else OSError | ||
|
||
|
||
def raise_on_exist_ro_file(filename): | ||
try: | ||
file_stat = os.stat(filename) # use stat to do exists + can write to check without race condition | ||
except OSError: | ||
return None # swallow does not exist or other errors | ||
|
||
if file_stat.st_mtime != 0: # if os.stat returns but modification is zero that's an invalid os.stat - ignore it | ||
if not (file_stat.st_mode & stat.S_IWUSR): | ||
raise PermissionError("Permission denied: {!r}".format(filename)) | ||
|
||
|
||
__all__ = [ | ||
"raise_on_exist_ro_file", | ||
"PermissionError", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,3 +113,6 @@ max-line-length = 120 | |
|
||
[pep8] | ||
max-line-length = 120 | ||
|
||
[pytest] | ||
timeout = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters