storage/blockchain: use os.replace
This commit is contained in:
@@ -352,11 +352,7 @@ class Blockchain(util.PrintError):
|
|||||||
self._forkpoint_hash, parent._forkpoint_hash = parent._forkpoint_hash, hash_raw_header(bh2u(parent_data[:HEADER_SIZE]))
|
self._forkpoint_hash, parent._forkpoint_hash = parent._forkpoint_hash, hash_raw_header(bh2u(parent_data[:HEADER_SIZE]))
|
||||||
self._prev_hash, parent._prev_hash = parent._prev_hash, self._prev_hash
|
self._prev_hash, parent._prev_hash = parent._prev_hash, self._prev_hash
|
||||||
# parent's new name
|
# parent's new name
|
||||||
try:
|
os.replace(child_old_name, parent.path())
|
||||||
os.rename(child_old_name, parent.path())
|
|
||||||
except OSError:
|
|
||||||
os.remove(parent.path())
|
|
||||||
os.rename(child_old_name, parent.path())
|
|
||||||
self.update_size()
|
self.update_size()
|
||||||
parent.update_size()
|
parent.update_size()
|
||||||
# update pointers
|
# update pointers
|
||||||
|
|||||||
@@ -122,12 +122,7 @@ class JsonDB(PrintError):
|
|||||||
os.fsync(f.fileno())
|
os.fsync(f.fileno())
|
||||||
|
|
||||||
mode = os.stat(self.path).st_mode if os.path.exists(self.path) else stat.S_IREAD | stat.S_IWRITE
|
mode = os.stat(self.path).st_mode if os.path.exists(self.path) else stat.S_IREAD | stat.S_IWRITE
|
||||||
# perform atomic write on POSIX systems
|
os.replace(temp_path, self.path)
|
||||||
try:
|
|
||||||
os.rename(temp_path, self.path)
|
|
||||||
except OSError:
|
|
||||||
os.remove(self.path)
|
|
||||||
os.rename(temp_path, self.path)
|
|
||||||
os.chmod(self.path, mode)
|
os.chmod(self.path, mode)
|
||||||
self.print_error("saved", self.path)
|
self.print_error("saved", self.path)
|
||||||
self.modified = False
|
self.modified = False
|
||||||
|
|||||||
Reference in New Issue
Block a user