Revision 41a57aab
b/lib/backend.py | ||
---|---|---|
26 | 26 |
import os.path |
27 | 27 |
import shutil |
28 | 28 |
import time |
29 |
import tempfile |
|
30 | 29 |
import stat |
31 | 30 |
import errno |
32 | 31 |
import re |
... | ... | |
939 | 938 |
" upload targets: '%s'" % file_name) |
940 | 939 |
return False |
941 | 940 |
|
942 |
dir_name, small_name = os.path.split(file_name) |
|
943 |
fd, new_name = tempfile.mkstemp('.new', small_name, dir_name) |
|
944 |
# here we need to make sure we remove the temp file, if any error |
|
945 |
# leaves it in place |
|
946 |
try: |
|
947 |
os.chown(new_name, uid, gid) |
|
948 |
os.chmod(new_name, mode) |
|
949 |
os.write(fd, data) |
|
950 |
os.fsync(fd) |
|
951 |
os.utime(new_name, (atime, mtime)) |
|
952 |
os.rename(new_name, file_name) |
|
953 |
finally: |
|
954 |
os.close(fd) |
|
955 |
utils.RemoveFile(new_name) |
|
941 |
utils.WriteFile(file_name, data=data, mode=mode, uid=uid, gid=gid, |
|
942 |
atime=atime, mtime=mtime) |
|
956 | 943 |
return True |
957 | 944 |
|
958 | 945 |
|
b/lib/ssconf.py | ||
---|---|---|
26 | 26 |
|
27 | 27 |
""" |
28 | 28 |
|
29 |
import os |
|
30 |
import tempfile |
|
31 |
import errno |
|
32 | 29 |
import socket |
33 | 30 |
|
34 | 31 |
from ganeti import errors |
35 | 32 |
from ganeti import constants |
33 |
from ganeti import utils |
|
36 | 34 |
|
37 | 35 |
|
38 | 36 |
class SimpleStore: |
... | ... | |
164 | 162 |
|
165 | 163 |
""" |
166 | 164 |
file_name = self.KeyToFilename(key) |
167 |
dir_name, small_name = os.path.split(file_name) |
|
168 |
fd, new_name = tempfile.mkstemp('.new', small_name, dir_name) |
|
169 |
# here we need to make sure we remove the temp file, if any error |
|
170 |
# leaves it in place |
|
171 |
try: |
|
172 |
os.chown(new_name, 0, 0) |
|
173 |
os.chmod(new_name, 0400) |
|
174 |
os.write(fd, "%s\n" % str(value)) |
|
175 |
os.fsync(fd) |
|
176 |
os.rename(new_name, file_name) |
|
177 |
self._cache[key] = value |
|
178 |
finally: |
|
179 |
os.close(fd) |
|
180 |
try: |
|
181 |
os.unlink(new_name) |
|
182 |
except OSError, err: |
|
183 |
if err.errno != errno.ENOENT: |
|
184 |
raise |
|
165 |
utils.WriteFile(file_name, data="%s\n" % str(value), |
|
166 |
uid=0, gid=0, mode=0400) |
|
167 |
self._cache[key] = value |
|
185 | 168 |
|
186 | 169 |
def GetFileList(self): |
187 | 170 |
"""Return the lis of all config files. |
Also available in: Unified diff