Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error logging and recovery #94

Merged
merged 13 commits into from
May 13, 2019
33 changes: 32 additions & 1 deletion platform_storage_api/fs/local.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import abc
import asyncio
import enum
import errno
import io
import logging
import os
Expand Down Expand Up @@ -203,7 +204,37 @@ async def get_filestatus(self, path: PurePath) -> FileStatus:
def _remove(self, path: PurePath) -> None:
concrete_path = Path(path)
if concrete_path.is_dir():
shutil.rmtree(concrete_path)
try:
shutil.rmtree(concrete_path)
except OSError as e:
# Debug logging
path = e.filename
path_access_ok = os.access(path, os.W_OK)
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to output a mode.

try:
    path_mode = f"{os.stat(path).st_mode:03o}"
except OSError:
    path_mode = '?'

try:
path_mode = f"{os.stat(path).st_mode:03o}"
except OSError:
path_mode = "?"

parent_path = os.path.dirname(path)
parent_path_access_ok = os.access(parent_path, os.W_OK)
try:
parent_path_mode = f"{os.stat(parent_path).st_mode:03o}"
except OSError:
parent_path_mode = "?"

logger.warning(
"OSError for path = %s, path_mode = %s, access = %s, "
"parent_path_mode = %s, parent_access = %s, "
"error_message = %s, errno = %s",
path,
path_mode,
path_access_ok,
parent_path_mode,
parent_path_access_ok,
str(e),
errno.errorcode.get(e.errno, e.errno),
)
raise e
else:
concrete_path.unlink()

Expand Down