Skip to content

Commit

Permalink
[Fixes #12124] GNIP 100: Assets - cleanup tmp doc file
Browse files Browse the repository at this point in the history
  • Loading branch information
etj committed May 10, 2024
1 parent 1e3b401 commit da90a2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion geonode/assets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def create_asset_and_link(
asset = link = None
try:
default_title, default_ext = os.path.splitext(files[0]) if len(files) == 1 else (None, None)
link_type = link_type or find_type(default_ext[1:]) if default_ext else None
if default_ext:
default_ext = default_ext.lstrip(".")
link_type = link_type or find_type(default_ext) if default_ext else None

asset = asset_handler.create(
title=title or default_title or "Unknown",
Expand Down
9 changes: 7 additions & 2 deletions geonode/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,13 @@ def form_valid(self, form):
files=[storage_path],
),
)
if tempdir != os.path.dirname(storage_path):
shutil.rmtree(tempdir, ignore_errors=True)

# Removing the temp file
# TODO: creating a file and then cloning it as an Asset may be slow: we may want to
# create the file directly in the asset dir or to move it
logger.info(f"Removing document temp dir {tempdir}")
shutil.rmtree(tempdir, ignore_errors=True)

else:
self.object = resource_manager.create(
None,
Expand Down

0 comments on commit da90a2a

Please sign in to comment.