On sync, if the symlink already exists, an exception would
be thrown. This change removes the file if it already
exists.
Bug 1132
Change-Id: I151a96adcac5d7cd51b84c2770f498a78d7d68be
Signed-off-by: beierlm <mark.beierl@canonical.com>
(cherry picked from commit
6d72d5cfb6f75c62402d493fdc2d81797cd48081)
# contact: eduardo.sousa@canonical.com
##
# contact: eduardo.sousa@canonical.com
##
+import errno
+from http import HTTPStatus
from io import BytesIO, StringIO
from io import BytesIO, StringIO
-from pymongo import MongoClient
-from gridfs import GridFSBucket, errors
-from http import HTTPStatus
+
+from gridfs import GridFSBucket, errors
from osm_common.fsbase import FsBase, FsException
from osm_common.fsbase import FsBase, FsException
+from pymongo import MongoClient
+
__author__ = "Eduardo Sousa <eduardo.sousa@canonical.com>"
__author__ = "Eduardo Sousa <eduardo.sousa@canonical.com>"
self.fs.download_to_stream(writing_file._id, b)
b.seek(0)
link = b.read().decode("utf-8")
self.fs.download_to_stream(writing_file._id, b)
b.seek(0)
link = b.read().decode("utf-8")
+
+ try:
+ os.remove(file_path)
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ # This is probably permission denied or worse
+ raise
os.symlink(link, file_path)
else:
with open(file_path, 'wb+') as file_stream:
os.symlink(link, file_path)
else:
with open(file_path, 'wb+') as file_stream:
if requested_file.metadata["type"] == mode:
return True
if requested_file.metadata["type"] == mode:
return True
if requested_file.metadata["type"] == "sym" and mode == "file":
return True
if requested_file.metadata["type"] == "sym" and mode == "file":
return True
else:
self.fs.delete(requested_file._id)
if not found and not ignore_non_exist:
else:
self.fs.delete(requested_file._id)
if not found and not ignore_non_exist:
- raise FsException("File {} does not exist".format(storage), http_code=HTTPStatus.NOT_FOUND)
+ raise FsException("File {} does not exist".format(storage), http_code=HTTPStatus.NOT_FOUND)
except IOError as e:
raise FsException("File {} cannot be deleted: {}".format(f, e), http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
except IOError as e:
raise FsException("File {} cannot be deleted: {}".format(f, e), http_code=HTTPStatus.INTERNAL_SERVER_ERROR)