Jun Omae committed 9b449f9

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

Comments (0)

Files changed (1)


 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 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,