Commit 30c7f89c authored by ben's avatar ben

Added David S.'s major/minor patch in cmodule.c,

SetConnections.py now normalizes rpaths,
log.py now returns LoggerError if can't open logfile,
Main.py catches logger error if can't open restore log


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@216 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 205aa667
...@@ -390,13 +390,24 @@ def RestoreAsOf(rpin, target): ...@@ -390,13 +390,24 @@ def RestoreAsOf(rpin, target):
def restore_common(rpin, target, time): def restore_common(rpin, target, time):
"""Restore operation common to Restore and RestoreAsOf""" """Restore operation common to Restore and RestoreAsOf"""
Log("Starting Restore", 5)
mirror_root, index = restore_get_root(rpin) mirror_root, index = restore_get_root(rpin)
mirror = mirror_root.new_index(index) mirror = mirror_root.new_index(index)
inc_rpath = datadir.append_path('increments', index) inc_rpath = datadir.append_path('increments', index)
restore_init_select(mirror_root, target) restore_init_select(mirror_root, target)
Log.open_logfile(datadir.append("restore.log")) restore_start_log(rpin, target, time)
Restore.Restore(inc_rpath, mirror, target, time) Restore.Restore(inc_rpath, mirror, target, time)
Log("Restore ended", 4)
def restore_start_log(rpin, target, time):
"""Open restore log file, log initial message"""
try: Log.open_logfile(datadir.append("restore.log"))
except LoggerError, e: Log("Warning, " + str(e), 2)
# Log following message at file verbosity 3, but term verbosity 4
log_message = ("Starting restore of %s to %s as it was as of %s." %
(rpin.path, target.path, Time.timetopretty(time)))
if Log.term_verbosity >= 4: Log.log_to_term(log_message, 4)
if Log.verbosity >= 3: Log.log_to_file(log_message)
def restore_check_paths(rpin, rpout, restoreasof = None): def restore_check_paths(rpin, rpout, restoreasof = None):
"""Check paths and return pair of corresponding rps""" """Check paths and return pair of corresponding rps"""
......
...@@ -55,11 +55,11 @@ def get_cmd_pairs(arglist, remote_schema = None, remote_cmd = None): ...@@ -55,11 +55,11 @@ def get_cmd_pairs(arglist, remote_schema = None, remote_cmd = None):
return cmdpairs return cmdpairs
def cmdpair2rp(cmd_pair): def cmdpair2rp(cmd_pair):
"""Return RPath from cmd_pair (remote_cmd, filename)""" """Return normalized RPath from cmd_pair (remote_cmd, filename)"""
cmd, filename = cmd_pair cmd, filename = cmd_pair
if cmd: conn = init_connection(cmd) if cmd: conn = init_connection(cmd)
else: conn = Globals.local_connection else: conn = Globals.local_connection
return RPath(conn, filename) return RPath(conn, filename).normalize()
def desc2cmd_pairs(desc_pair): def desc2cmd_pairs(desc_pair):
"""Return pair (remote_cmd, filename) from desc_pair""" """Return pair (remote_cmd, filename) from desc_pair"""
......
...@@ -129,12 +129,12 @@ static PyObject *c_make_file_dict(self, args) ...@@ -129,12 +129,12 @@ static PyObject *c_make_file_dict(self, args)
char devtype[2]; char devtype[2];
#if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS) #if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS)
LONG_LONG devnums = (LONG_LONG)sbuf.st_rdev; LONG_LONG devnums = (LONG_LONG)sbuf.st_rdev;
PyObject *major_num = PyLong_FromLongLong(devnums >> 8); PyObject *major_num = PyLong_FromLongLong(major(devnums));
#else #else
long int devnums = (long)sbuf.st_dev; long int devnums = (long)sbuf.st_dev;
PyObject *major_num = PyInt_FromLong(devnums >> 8); PyObject *major_num = PyInt_FromLong(devnums >> 8);
#endif #endif
int minor_num = (int)(devnums & 0xff); int minor_num = (int)(minor(devnums));
if S_ISCHR(mode) strcpy(devtype, "c"); if S_ISCHR(mode) strcpy(devtype, "c");
else strcpy(devtype, "b"); else strcpy(devtype, "b");
return_val = Py_BuildValue("{s:s,s:O,s:l,s:l,s:l,s:O,s:O,s:l,s:N}", return_val = Py_BuildValue("{s:s,s:O,s:l,s:l,s:l,s:O,s:O,s:l,s:N}",
......
...@@ -37,7 +37,7 @@ class Logger: ...@@ -37,7 +37,7 @@ class Logger:
try: self.term_verbosity = int(termverb_string) try: self.term_verbosity = int(termverb_string)
except ValueError: except ValueError:
Log.FatalError("Terminal verbosity must be a number, received " Log.FatalError("Terminal verbosity must be a number, received "
"'%s' insteaxd." % termverb_string) "'%s' instead." % termverb_string)
self.termverbset = 1 self.termverbset = 1
def open_logfile(self, rpath): def open_logfile(self, rpath):
...@@ -48,9 +48,9 @@ class Logger: ...@@ -48,9 +48,9 @@ class Logger:
""" """
assert not self.log_file_open assert not self.log_file_open
rpath.conn.Log.open_logfile_local(rpath)
for conn in Globals.connections: for conn in Globals.connections:
conn.Log.open_logfile_allconn(rpath.conn) conn.Log.open_logfile_allconn(rpath.conn)
rpath.conn.Log.open_logfile_local(rpath)
def open_logfile_allconn(self, log_file_conn): def open_logfile_allconn(self, log_file_conn):
"""Run on all connections to signal log file is open""" """Run on all connections to signal log file is open"""
...@@ -59,10 +59,13 @@ class Logger: ...@@ -59,10 +59,13 @@ class Logger:
def open_logfile_local(self, rpath): def open_logfile_local(self, rpath):
"""Open logfile locally - should only be run on one connection""" """Open logfile locally - should only be run on one connection"""
assert self.log_file_conn is Globals.local_connection assert rpath.conn is Globals.local_connection
try: self.logfp = rpath.open("a")
except (OSError, IOError), e:
raise LoggerError("Unable to open logfile %s: %s"
% (rpath.path, e))
self.log_file_local = 1 self.log_file_local = 1
self.logrp = rpath self.logrp = rpath
self.logfp = rpath.open("a")
def close_logfile(self): def close_logfile(self):
"""Close logfile and inform all connections""" """Close logfile and inform all connections"""
......
...@@ -390,13 +390,24 @@ def RestoreAsOf(rpin, target): ...@@ -390,13 +390,24 @@ def RestoreAsOf(rpin, target):
def restore_common(rpin, target, time): def restore_common(rpin, target, time):
"""Restore operation common to Restore and RestoreAsOf""" """Restore operation common to Restore and RestoreAsOf"""
Log("Starting Restore", 5)
mirror_root, index = restore_get_root(rpin) mirror_root, index = restore_get_root(rpin)
mirror = mirror_root.new_index(index) mirror = mirror_root.new_index(index)
inc_rpath = datadir.append_path('increments', index) inc_rpath = datadir.append_path('increments', index)
restore_init_select(mirror_root, target) restore_init_select(mirror_root, target)
Log.open_logfile(datadir.append("restore.log")) restore_start_log(rpin, target, time)
Restore.Restore(inc_rpath, mirror, target, time) Restore.Restore(inc_rpath, mirror, target, time)
Log("Restore ended", 4)
def restore_start_log(rpin, target, time):
"""Open restore log file, log initial message"""
try: Log.open_logfile(datadir.append("restore.log"))
except LoggerError, e: Log("Warning, " + str(e), 2)
# Log following message at file verbosity 3, but term verbosity 4
log_message = ("Starting restore of %s to %s as it was as of %s." %
(rpin.path, target.path, Time.timetopretty(time)))
if Log.term_verbosity >= 4: Log.log_to_term(log_message, 4)
if Log.verbosity >= 3: Log.log_to_file(log_message)
def restore_check_paths(rpin, rpout, restoreasof = None): def restore_check_paths(rpin, rpout, restoreasof = None):
"""Check paths and return pair of corresponding rps""" """Check paths and return pair of corresponding rps"""
......
...@@ -55,11 +55,11 @@ def get_cmd_pairs(arglist, remote_schema = None, remote_cmd = None): ...@@ -55,11 +55,11 @@ def get_cmd_pairs(arglist, remote_schema = None, remote_cmd = None):
return cmdpairs return cmdpairs
def cmdpair2rp(cmd_pair): def cmdpair2rp(cmd_pair):
"""Return RPath from cmd_pair (remote_cmd, filename)""" """Return normalized RPath from cmd_pair (remote_cmd, filename)"""
cmd, filename = cmd_pair cmd, filename = cmd_pair
if cmd: conn = init_connection(cmd) if cmd: conn = init_connection(cmd)
else: conn = Globals.local_connection else: conn = Globals.local_connection
return RPath(conn, filename) return RPath(conn, filename).normalize()
def desc2cmd_pairs(desc_pair): def desc2cmd_pairs(desc_pair):
"""Return pair (remote_cmd, filename) from desc_pair""" """Return pair (remote_cmd, filename) from desc_pair"""
......
...@@ -129,12 +129,12 @@ static PyObject *c_make_file_dict(self, args) ...@@ -129,12 +129,12 @@ static PyObject *c_make_file_dict(self, args)
char devtype[2]; char devtype[2];
#if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS) #if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS)
LONG_LONG devnums = (LONG_LONG)sbuf.st_rdev; LONG_LONG devnums = (LONG_LONG)sbuf.st_rdev;
PyObject *major_num = PyLong_FromLongLong(devnums >> 8); PyObject *major_num = PyLong_FromLongLong(major(devnums));
#else #else
long int devnums = (long)sbuf.st_dev; long int devnums = (long)sbuf.st_dev;
PyObject *major_num = PyInt_FromLong(devnums >> 8); PyObject *major_num = PyInt_FromLong(devnums >> 8);
#endif #endif
int minor_num = (int)(devnums & 0xff); int minor_num = (int)(minor(devnums));
if S_ISCHR(mode) strcpy(devtype, "c"); if S_ISCHR(mode) strcpy(devtype, "c");
else strcpy(devtype, "b"); else strcpy(devtype, "b");
return_val = Py_BuildValue("{s:s,s:O,s:l,s:l,s:l,s:O,s:O,s:l,s:N}", return_val = Py_BuildValue("{s:s,s:O,s:l,s:l,s:l,s:O,s:O,s:l,s:N}",
......
...@@ -37,7 +37,7 @@ class Logger: ...@@ -37,7 +37,7 @@ class Logger:
try: self.term_verbosity = int(termverb_string) try: self.term_verbosity = int(termverb_string)
except ValueError: except ValueError:
Log.FatalError("Terminal verbosity must be a number, received " Log.FatalError("Terminal verbosity must be a number, received "
"'%s' insteaxd." % termverb_string) "'%s' instead." % termverb_string)
self.termverbset = 1 self.termverbset = 1
def open_logfile(self, rpath): def open_logfile(self, rpath):
...@@ -48,9 +48,9 @@ class Logger: ...@@ -48,9 +48,9 @@ class Logger:
""" """
assert not self.log_file_open assert not self.log_file_open
rpath.conn.Log.open_logfile_local(rpath)
for conn in Globals.connections: for conn in Globals.connections:
conn.Log.open_logfile_allconn(rpath.conn) conn.Log.open_logfile_allconn(rpath.conn)
rpath.conn.Log.open_logfile_local(rpath)
def open_logfile_allconn(self, log_file_conn): def open_logfile_allconn(self, log_file_conn):
"""Run on all connections to signal log file is open""" """Run on all connections to signal log file is open"""
...@@ -59,10 +59,13 @@ class Logger: ...@@ -59,10 +59,13 @@ class Logger:
def open_logfile_local(self, rpath): def open_logfile_local(self, rpath):
"""Open logfile locally - should only be run on one connection""" """Open logfile locally - should only be run on one connection"""
assert self.log_file_conn is Globals.local_connection assert rpath.conn is Globals.local_connection
try: self.logfp = rpath.open("a")
except (OSError, IOError), e:
raise LoggerError("Unable to open logfile %s: %s"
% (rpath.path, e))
self.log_file_local = 1 self.log_file_local = 1
self.logrp = rpath self.logrp = rpath
self.logfp = rpath.open("a")
def close_logfile(self): def close_logfile(self):
"""Close logfile and inform all connections""" """Close logfile and inform all connections"""
......
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