"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "fsmove/src/io/io.cc" between
fstransform-0.9.3-src.tar.gz and fstransform-0.9.4.tar.gz

About: fstransform is a tool to change a file-system from one format to another, for example from jfs, xfs, or reiser to ext2, ext3, or ext4, in-place and without the need for backup.

io.cc  (fstransform-0.9.3-src):io.cc  (fstransform-0.9.4)
skipping to change at line 29 skipping to change at line 29
* *
* io/io.cc * io/io.cc
* *
* Created on: Sep 20, 2011 * Created on: Sep 20, 2011
* Author: max * Author: max
*/ */
#include "../first.hh" #include "../first.hh"
#include "../args.hh" // for fm_args #include "../args.hh" // for fm_args
#include "../assert.hh" // for ff_assert()
#include "../misc.hh" // for ff_show_progress(), ff_now() #include "../misc.hh" // for ff_show_progress(), ff_now()
#include "io.hh" // for fm_io #include "io.hh" // for fm_io
#include "cache/cache_mem.hh" // for ft_cache_mem
#include "cache/cache_symlink.hh" // for ft_cache_symlink_kv
#if defined(FT_HAVE_MATH_H) #if defined(FT_HAVE_MATH_H)
# include <math.h> // for sqrt() # include <math.h> // for sqrt()
#elif defined(FT_HAVE_CMATH) #elif defined(FT_HAVE_CMATH)
# include <cmath> // for sqrt() # include <cmath> // for sqrt()
#endif #endif
#if defined(FT_HAVE_STRING_H)
# include <string.h> // for strcmp()
#elif defined(FT_HAVE_CSTRING)
# include <cstring> // for strcmp()
#endif
FT_IO_NAMESPACE_BEGIN FT_IO_NAMESPACE_BEGIN
char const * const fm_io::label[] = { char const * const fm_io::label[] = {
"source", "target" "source", "target"
}; };
char const * const fm_io::LABEL[] = { char const * const fm_io::LABEL[] = {
"SOURCE", "TARGET" "SOURCE", "TARGET"
}; };
/** constructor */ /** constructor */
fm_io::fm_io() fm_io::fm_io()
: this_inode_cache(), this_exclude_set(), : this_inode_cache(NULL), this_exclude_set(),
this_source_stat(), this_target_stat(), this_source_stat(), this_target_stat(),
this_source_root(), this_target_root(), this_source_root(), this_target_root(),
this_eta(), this_work_total(0), this_work_report_threshold(0), this_eta(), this_work_total(0), this_work_report_threshold(0),
this_work_done(0), this_work_last_reported(0), this_work_done(0), this_work_last_reported(0),
this_work_last_reported_time(0.0), this_force_run(false), this_simulate_ru this_work_last_reported_time(0.0),
n(false) this_progress_msg(NULL), this_force_run(false), this_simulate_run(false)
{ } { }
/** /**
* destructor. * destructor.
* sub-classes must override it to call close() * sub-classes must override it to call close()
*/ */
fm_io::~fm_io() fm_io::~fm_io()
{ } {
// in case it's != NULL
delete this_inode_cache;
}
/** /**
* open this fm_io. * open this fm_io.
* sub-classes must override this method to perform appropriate initialization * sub-classes must override this method to perform appropriate initialization
*/ */
int fm_io::open(const fm_args & args) int fm_io::open(const fm_args & args)
{ {
const char * arg1 = args.io_args[FC_SOURCE_ROOT], * arg2 = args.io_args[FC_T ARGET_ROOT]; const char * arg1 = args.io_args[FC_SOURCE_ROOT], * arg2 = args.io_args[FC_T ARGET_ROOT];
int err = 0; int err = 0;
do { do {
if (arg1 == NULL) { if (arg1 == NULL) {
ff_log(FC_ERROR, 0, "missing arguments: %s %s", label[FC_SOURCE_ROOT ], label[FC_TARGET_ROOT]); ff_log(FC_ERROR, 0, "missing arguments: %s %s", label[FC_SOURCE_ROOT ], label[FC_TARGET_ROOT]);
err = -EINVAL; err = -EINVAL;
break; break;
} }
if (arg2 == NULL) { if (arg2 == NULL) {
ff_log(FC_ERROR, 0, "missing argument: %s", label[FC_TARGET_ROOT]); ff_log(FC_ERROR, 0, "missing argument: %s", label[FC_TARGET_ROOT]);
err = -EINVAL; err = -EINVAL;
break; break;
} }
const char * inode_cache_path = args.inode_cache_path;
delete this_inode_cache;
this_inode_cache = NULL;
if (inode_cache_path != NULL)
{
ft_cache_symlink_kv<ft_inode, ft_string> * icp = new ft_cache_sym
link_kv<ft_inode, ft_string>(inode_cache_path);
err = icp->init(inode_cache_path);
if (err != 0)
{
delete icp;
break;
}
// icp->get_path() removes trailing '/' unless it's exactly the p
ath "/"
inode_cache_path = icp->get_path();
this_inode_cache = icp;
}
else
this_inode_cache = new ft_cache_mem<ft_inode,ft_string>();
this_source_stat.set_name("source"); this_source_stat.set_name("source");
this_target_stat.set_name("target"); this_target_stat.set_name("target");
this_source_root = arg1; this_source_root = arg1;
this_target_root = arg2; this_target_root = arg2;
this_eta.clear(); this_eta.clear();
this_work_total = this_work_report_threshold = this_work_done = this_wor k_last_reported = 0; this_work_total = this_work_report_threshold = this_work_done = this_wor k_last_reported = 0;
this_force_run = args.force_run; this_force_run = args.force_run;
this_simulate_run = args.simulate_run; this_simulate_run = args.simulate_run;
this_progress_msg = " still to move";
char const * const * exclude_list = args.exclude_list; char const * const * exclude_list = args.exclude_list;
if (exclude_list != NULL) { if (exclude_list != NULL) {
for (; * exclude_list != NULL; ++exclude_list) for (; * exclude_list != NULL; ++exclude_list)
this_exclude_set.insert(* exclude_list); this_exclude_set.insert(* exclude_list);
} }
// do NOT move the inode-cache!
if (inode_cache_path != NULL)
{
this_exclude_set.insert(inode_cache_path);
}
} while (0); } while (0);
return err; return err;
} }
int fm_io::inode_cache_find_or_add(ft_inode inode, ft_string & path)
{
ft_size root_len = this_target_root.length();
ff_assert(path.length() >= root_len && path.compare(0, root_len, this_tar
get_root) == 0);
ft_string short_path = path.substr(root_len);
int err = this_inode_cache->find_or_add(inode, short_path);
if (err == 1)
path = this_target_root + short_path;
return err;
}
int fm_io::inode_cache_find_and_delete(ft_inode inode, ft_string & path)
{
ft_size root_len = this_target_root.length();
ff_assert(path.length() >= root_len && path.compare(0, root_len, this_tar
get_root) == 0);
ft_string short_path = path.substr(root_len);
int err = this_inode_cache->find_and_delete(inode, short_path);
if (err == 1)
path = this_target_root + short_path;
return err;
}
/** /**
* returns error if source or target file-system are almost full (typical thresh old is 97%) * returns error if source or target file-system are almost full (typical thresh old is 97%)
*/ */
int fm_io::is_almost_full(const fm_disk_stat & stat) const int fm_io::is_almost_full(const fm_disk_stat & stat) const
{ {
ft_uoff total = stat.get_total(); ft_uoff total = stat.get_total();
int err = 0; int err = 0;
if (total != 0) { if (total != 0) {
ft_uoff used = stat.get_used(); ft_uoff used = stat.get_used();
double percentage = 100.0 * ((double) used / total); double percentage = 100.0 * ((double) used / total);
skipping to change at line 206 skipping to change at line 271
percentage = moved_len / (double)work_total; percentage = moved_len / (double)work_total;
time_left = this_eta.add(percentage); time_left = this_eta.add(percentage);
percentage *= 100.0; percentage *= 100.0;
const char * simul_msg = ""; const char * simul_msg = "";
if (simulate_run()) { if (simulate_run()) {
simul_msg = "(simulated) "; simul_msg = "(simulated) ";
time_left = -1.0; time_left = -1.0;
} }
ff_show_progress(log_level, simul_msg, percentage, work_total - moved_len, " still to move", time_left); ff_show_progress(log_level, simul_msg, percentage, work_total - moved_len, t his_progress_msg, time_left);
} }
/** /**
* close this fm_io. * close this fm_io.
* sub-classes must override this method to perform appropriate cleanup * sub-classes must override this method to perform appropriate cleanup
*/ */
void fm_io::close() void fm_io::close()
{ {
this_inode_cache.clear(); this_exclude_set.clear();
this_exclude_set.clear();
this_source_stat.clear(); this_source_stat.clear();
this_target_stat.clear(); this_target_stat.clear();
this_source_root.clear(); this_source_root.clear();
this_target_root.clear(); this_target_root.clear();
this_eta.clear(); this_eta.clear();
this_work_done = this_work_last_reported = this_work_total = 0; this_work_done = this_work_last_reported = this_work_total = 0;
this_force_run = false; this_progress_msg = NULL;
this_simulate_run = false; this_force_run = this_simulate_run = false;
delete this_inode_cache;
this_inode_cache = NULL;
} }
FT_IO_NAMESPACE_END FT_IO_NAMESPACE_END
 End of changes. 14 change blocks. 
9 lines changed or deleted 79 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)