1. Jun Omae
  2. trac


Jun Omae  committed 9b449f9

Use `os.rmdir` instead of `shutil.rmtree`. We should remove old attachments directory if empty.

  • Participants
  • Parent commits aae5292
  • Branches t10313-hashed-path

Comments (0)

Files changed (1)

File trac/attachment.py

View file
 from trac.util.datefmt import format_datetime, from_utimestamp, \
                               to_datetime, to_utimestamp, utc
 from trac.util.text import exception_to_unicode, pretty_size, print_table, \
-                           unicode_quote, unicode_unquote
+                           unicode_quote, unicode_unquote, printerr
 from trac.util.translation import _, tag_
 from trac.web import HTTPBadRequest, IRequestHandler, RequestDone
 from trac.web.chrome import (INavigationContributor, add_ctxtnav, add_link,
-        shutil.rmtree(os.path.join(path, 'attachments'))
+        old_dir = os.path.join(path, 'attachments')
+        try:
+            os.rmdir(old_dir)
+        except OSError, e:
+            self.log.error("Can't delete old attachments directory %s: %s",
+                           old_dir, exception_to_unicode(e, traceback=True))
+            printerr(_("Error while deleting old attachments directory. "
+                       "Please move or remove files in\nthe directory and try "
+                       "again."))
+            raise
     def _move_attachment_file(self, attachment):
         old_path = attachment._get_path_old(attachment.parent_realm,