Commit 41a57aab authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Replace custom file writing code with utils.WriteFile

Reviewed-by: ultrotter
parent 7c0d6283
......@@ -26,7 +26,6 @@ import os
import os.path
import shutil
import time
import tempfile
import stat
import errno
import re
......@@ -939,20 +938,8 @@ def UploadFile(file_name, data, mode, uid, gid, atime, mtime):
" upload targets: '%s'" % file_name)
return False
dir_name, small_name = os.path.split(file_name)
fd, new_name = tempfile.mkstemp('.new', small_name, dir_name)
# here we need to make sure we remove the temp file, if any error
# leaves it in place
try:
os.chown(new_name, uid, gid)
os.chmod(new_name, mode)
os.write(fd, data)
os.fsync(fd)
os.utime(new_name, (atime, mtime))
os.rename(new_name, file_name)
finally:
os.close(fd)
utils.RemoveFile(new_name)
utils.WriteFile(file_name, data=data, mode=mode, uid=uid, gid=gid,
atime=atime, mtime=mtime)
return True
......
......@@ -26,13 +26,11 @@ configuration data, which is mostly static and available to all nodes.
"""
import os
import tempfile
import errno
import socket
from ganeti import errors
from ganeti import constants
from ganeti import utils
class SimpleStore:
......@@ -164,24 +162,9 @@ class SimpleStore:
"""
file_name = self.KeyToFilename(key)
dir_name, small_name = os.path.split(file_name)
fd, new_name = tempfile.mkstemp('.new', small_name, dir_name)
# here we need to make sure we remove the temp file, if any error
# leaves it in place
try:
os.chown(new_name, 0, 0)
os.chmod(new_name, 0400)
os.write(fd, "%s\n" % str(value))
os.fsync(fd)
os.rename(new_name, file_name)
self._cache[key] = value
finally:
os.close(fd)
try:
os.unlink(new_name)
except OSError, err:
if err.errno != errno.ENOENT:
raise
utils.WriteFile(file_name, data="%s\n" % str(value),
uid=0, gid=0, mode=0400)
self._cache[key] = value
def GetFileList(self):
"""Return the lis of all config files.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment