Add logging to filesystem driver
This approximates the logging in the swift driver in order to make it easier to compare behavior. Change-Id: If13c64d970d41306792699c362cd175840347763
This commit is contained in:
parent
a602f0a779
commit
9c9395df2c
@ -13,6 +13,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
@ -23,10 +24,13 @@ DISK_CHUNK_SIZE = 64 * 1024
|
|||||||
|
|
||||||
|
|
||||||
class FilesystemDriver(storageutils.StorageDriver):
|
class FilesystemDriver(storageutils.StorageDriver):
|
||||||
|
log = logging.getLogger('registry.filesystem')
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
self.root = conf['root']
|
self.root = conf['root']
|
||||||
|
|
||||||
def list_objects(self, path):
|
def list_objects(self, path):
|
||||||
|
self.log.debug("List objects %s", path)
|
||||||
path = os.path.join(self.root, path)
|
path = os.path.join(self.root, path)
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
return []
|
return []
|
||||||
@ -48,13 +52,18 @@ class FilesystemDriver(storageutils.StorageDriver):
|
|||||||
path = os.path.join(self.root, path)
|
path = os.path.join(self.root, path)
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
with open(path, 'wb') as f:
|
with open(path, 'wb') as f:
|
||||||
|
size = 0
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
size += len(data)
|
||||||
else:
|
else:
|
||||||
for chunk in data:
|
for chunk in data:
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
|
size += len(chunk)
|
||||||
f.flush()
|
f.flush()
|
||||||
os.fsync(f.fileno())
|
os.fsync(f.fileno())
|
||||||
|
self.log.debug("[u: %s] Upload object %s size: %s",
|
||||||
|
uuid, path, size)
|
||||||
|
|
||||||
def get_object(self, path):
|
def get_object(self, path):
|
||||||
path = os.path.join(self.root, path)
|
path = os.path.join(self.root, path)
|
||||||
@ -105,8 +114,12 @@ class FilesystemDriver(storageutils.StorageDriver):
|
|||||||
def move_object(self, src_path, dst_path, uuid=None):
|
def move_object(self, src_path, dst_path, uuid=None):
|
||||||
src_path = os.path.join(self.root, src_path)
|
src_path = os.path.join(self.root, src_path)
|
||||||
dst_path = os.path.join(self.root, dst_path)
|
dst_path = os.path.join(self.root, dst_path)
|
||||||
|
self.log.debug("[u: %s] Move object %s %s",
|
||||||
|
uuid, src_path, dst_path)
|
||||||
os.makedirs(os.path.dirname(dst_path), exist_ok=True)
|
os.makedirs(os.path.dirname(dst_path), exist_ok=True)
|
||||||
os.rename(src_path, dst_path)
|
os.rename(src_path, dst_path)
|
||||||
|
self.log.debug("[u: %s] Moved object %s %s",
|
||||||
|
uuid, src_path, dst_path)
|
||||||
|
|
||||||
def cat_objects(self, path, chunks, uuid=None):
|
def cat_objects(self, path, chunks, uuid=None):
|
||||||
path = os.path.join(self.root, path)
|
path = os.path.join(self.root, path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user