Commit b6f8b8d2 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

#Refs #447

parent 9887bd5e
import os import os
import sqlite3 import sqlite3
import json
import logging import logging
import types import types
import hashlib import hashlib
import shutil import shutil
import basebackend
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class BackEnd: class BackEnd(basebackend.BaseBackEnd):
def __init__(self, basepath): def __init__(self, basepath):
self.basepath = basepath self.basepath = basepath
...@@ -196,6 +196,10 @@ class BackEnd: ...@@ -196,6 +196,10 @@ class BackEnd:
fullname = os.path.join(self.basepath, account, container) fullname = os.path.join(self.basepath, account, container)
if not os.path.exists(fullname): if not os.path.exists(fullname):
raise NameError('Container does not exist') raise NameError('Container does not exist')
try:
link = self.__get_linkinfo(os.path.join(account, container, name))
except NameError:
raise NameError('Object does not exist')
self.__put_metadata(os.path.join(account, container, name), meta) self.__put_metadata(os.path.join(account, container, name), meta)
return return
...@@ -259,6 +263,8 @@ class BackEnd: ...@@ -259,6 +263,8 @@ class BackEnd:
dest_location = os.path.join(self.basepath, account, dest_container, link) dest_location = os.path.join(self.basepath, account, dest_container, link)
shutil.copyfile(src_location, dest_location) shutil.copyfile(src_location, dest_location)
# TODO: accept metadata changes
self.__put_metadata(os.path.join(account, dest_container, dest_name), self.__get_metadata(os.path.join(account, src_container, src_name)))
return return
def delete_object(self, account, container, name): def delete_object(self, account, container, name):
...@@ -306,8 +312,6 @@ class BackEnd: ...@@ -306,8 +312,6 @@ class BackEnd:
else: else:
link = self.con.execute('insert into objects (name) values (?)', (path,)).lastrowid link = self.con.execute('insert into objects (name) values (?)', (path,)).lastrowid
for k, v in meta.iteritems(): for k, v in meta.iteritems():
if type(v) != types.StringType:
v = json.dumps(v)
self.con.execute('insert or replace into metadata (object_id, name, value) values (?, ?, ?)', (link, k, v)) self.con.execute('insert or replace into metadata (object_id, name, value) values (?, ?, ?)', (link, k, v))
self.con.commit() self.con.commit()
return return
......
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