Skip to content

Commit

Permalink
Fallback to simple file copy if rename failed
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Apr 9, 2016
1 parent 1beb4fc commit 561bd80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Site/SiteStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def rename(self, inner_path_before, inner_path_after):
err = None
break
except Exception, err:
self.log.error("%s rename error: %s" % (inner_path_before, err))
self.log.error("%s rename error: %s (retry #%s)" % (inner_path_before, err, retry))
time.sleep(0.1 + retry)
if err:
raise err
Expand Down
12 changes: 9 additions & 3 deletions src/Ui/UiWebsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import hashlib
import os
import re
import shutil

import gevent

Expand Down Expand Up @@ -383,8 +383,14 @@ def actionFileWrite(self, to, inner_path, content_base64):
import base64
content = base64.b64decode(content_base64)
# Save old file to generate patch later
if self.site.storage.isFile(inner_path) and not self.site.storage.isFile(inner_path+"-old"):
self.site.storage.rename(inner_path, inner_path+"-old")
if inner_path.endswith(".json") and self.site.storage.isFile(inner_path) and not self.site.storage.isFile(inner_path + "-old"):
try:
self.site.storage.rename(inner_path, inner_path + "-old")
except Exception:
# Rename failed, fall back to standard file write
f_old = self.site.storage.open(inner_path, "rb")
f_new = self.site.storage.open(inner_path + "-old", "wb")
shutil.copyfileobj(f_old, f_new)

self.site.storage.write(inner_path, content)
except Exception, err:
Expand Down

0 comments on commit 561bd80

Please sign in to comment.