Commit aed77cea authored by Guido Trotter's avatar Guido Trotter
Browse files

FileStorage: abort creating over an existing file

In FileStorage there is a TODO:
 decide whether we should check for existing files and
 abort or not
After Ganeti ate my instance data I decided. Let's abort.
In general there is no reason we should overwrite existing files, and
doing it can be very harmful for preexisting files on the host.

Reviewed-by: iustinp
parent 6633774e
......@@ -1629,11 +1629,11 @@ class FileStorage(BlockDev):
@return: an instance of FileStorage
"""
# TODO: decide whether we should check for existing files and
# abort or not
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
raise ValueError("Invalid configuration data %s" % str(unique_id))
dev_path = unique_id[1]
if os.path.exists(dev_path):
_ThrowError("File already existing: %s", dev_path)
try:
f = open(dev_path, 'w')
f.truncate(size * 1024 * 1024)
......
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