Commit dbcb4a3d authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

fixes in localfs source handle

parent 3ad796e5
......@@ -370,7 +370,8 @@ class LocalfsSourceHandle(object):
def get_path_in_cache(self, name):
return utils.join_path(self.cache_path, name)
def lock_file(self, fspath):
def lock_file(self):
fspath = self.fspath
if file_is_open(fspath):
raise common.BusyError("File '%s' is open. Aborting"
% fspath)
......@@ -393,22 +394,26 @@ class LocalfsSourceHandle(object):
if e.errno == OS_NO_FILE_OR_DIR:
logger.info("Source does not exist: '%s'" % fspath)
self.unregister_stage_name(stage_filename)
self.check_update_source_state()
return
else:
raise e
if file_is_open(stage_path):
os.rename(stage_path, fspath)
self.unregister_stage_name(stage_filename)
logger.warning("File '%s' is open; unstaged" % self.objname)
raise common.BusyError("File '%s' is open. Undoing" % stage_path)
def stage_file(self):
self.lock_file()
if self.staged_path is not None:
if file_is_open(self.staged_path):
os.rename(self.staged_path, self.fspath)
self.unregister_stage_name(self.stage_filename)
logger.warning("File '%s' is open; unstaged" % self.objname)
raise common.BusyError("File '%s' is open. Undoing" %
self.staged_path)
if path_status(self.staged_path) != LOCAL_FILE:
os.rename(self.staged_path, self.fspath)
self.unregister_stage_name(self.stage_filename)
logger.warning("Object '%s' is not a regular file; unstaged" %
self.objname)
self.check_update_source_state()
if path_status(stage_path) != LOCAL_FILE:
os.rename(stage_path, fspath)
self.unregister_stage_name(stage_filename)
logger.warning("Object '%s' is not a regular file; unstaged" %
self.objname)
def __init__(self, settings, source_state):
self.settings = settings
......@@ -425,7 +430,7 @@ class LocalfsSourceHandle(object):
self.staged_path = None
self.heartbeat = settings.heartbeat
if self.needs_staging():
self.lock_file(self.fspath)
self.stage_file()
@transaction()
def update_state(self, state):
......@@ -469,20 +474,15 @@ class LocalfsSourceHandle(object):
os.rename(self.staged_path, stash_filename)
def unstage_file(self):
self.do_unstage()
self.unregister_stage_name(self.stage_filename)
def do_unstage(self):
if self.stage_filename is None:
return
if self.info_is_deleted():
return
staged_path = self.staged_path
try:
link_file(staged_path, self.fspath)
os.unlink(staged_path)
except common.ConflictError:
self.stash_staged_file()
self.unregister_stage_name(self.stage_filename)
class LocalfsFileClient(FileClient):
......
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