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

Faster cleanup of output folder (PEP-0471) #3356

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pelican/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,19 @@ def clean_output_dir(path: str, retention: Iterable[str]) -> None:
return

# remove existing content from output folder unless in retention list
for filename in os.listdir(path):
file = os.path.join(path, filename)
if any(filename == retain for retain in retention):
for dir_entry in os.scandir(path):
file = dir_entry.path
if any(dir_entry.name == retain for retain in retention):
logger.debug(
"Skipping deletion; %s is on retention list: %s", filename, file
"Skipping deletion; %s is on retention list: %s", dir_entry.name, file
)
elif os.path.isdir(file):
elif dir_entry.is_dir():
try:
shutil.rmtree(file)
logger.debug("Deleted directory %s", file)
except Exception as e:
logger.error("Unable to delete directory %s; %s", file, e)
elif os.path.isfile(file) or os.path.islink(file):
elif dir_entry.is_file(follow_symlinks=False) or dir_entry.is_symlink():
try:
os.remove(file)
logger.debug("Deleted file/link %s", file)
Expand Down