From 358caa78601ab56b5c90bf5cd279e0a328a927f8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 9 Nov 2000 21:42:59 +0000 Subject: [PATCH] *** empty log message *** --- pandatool/src/cvscopy/cvsCopy.cxx | 85 +++++++++++++++++--- pandatool/src/cvscopy/cvsCopy.h | 4 + pandatool/src/cvscopy/cvsSourceTree.cxx | 4 +- pandatool/src/egg-palettize/eggPalettize.cxx | 9 ++- pandatool/src/egg-palettize/eggPalettize.h | 1 + pandatool/src/fltprogs/fltCopy.cxx | 2 +- 6 files changed, 92 insertions(+), 13 deletions(-) diff --git a/pandatool/src/cvscopy/cvsCopy.cxx b/pandatool/src/cvscopy/cvsCopy.cxx index f4e56c9915..89df70c458 100644 --- a/pandatool/src/cvscopy/cvsCopy.cxx +++ b/pandatool/src/cvscopy/cvsCopy.cxx @@ -118,18 +118,24 @@ import(const Filename &source, void *extra_data, _tree.choose_directory(basename, suggested_dir, _force, _interactive); nassertr(dir != (CVSSourceDirectory *)NULL, dir); - nout << "Copying " << basename << " to " << dir->get_path() << "\n"; - + _copied_files[source] = dir; Filename dest = dir->get_fullpath() + "/" + basename; - _copied_files[source] = dir; - bool new_file = !dest.exists(); - if (!copy_file(source, dest, dir, extra_data, new_file)) { - return (CVSSourceDirectory *)NULL; - } - if (new_file) { - create_file(dest); + if (!new_file && verify_file(source, dest, dir, extra_data)) { + // The file is unchanged. + nout << dir->get_path() + "/" + basename << " is unchanged.\n"; + + } else { + // The file has changed. + nout << "Copying " << basename << " to " << dir->get_path() << "\n"; + + if (!copy_file(source, dest, dir, extra_data, new_file)) { + return (CVSSourceDirectory *)NULL; + } + if (new_file) { + create_file(dest); + } } return dir; @@ -200,6 +206,67 @@ post_command_line() { return true; } + +//////////////////////////////////////////////////////////////////// +// Function: CVSCopy::verify_file +// Access: Protected, Virtual +// Description: Verifies that the file is identical and does not need +// to be recopied. Returns true if the files are +// identical, false if they differ. +//////////////////////////////////////////////////////////////////// +bool CVSCopy:: +verify_file(const Filename &, const Filename &, + CVSSourceDirectory *, void *) { + return false; +} + +//////////////////////////////////////////////////////////////////// +// Function: CVSCopy::verify_binary_file +// Access: Protected +// Description: Verifies that the file is identical and does not need +// to be recopied. Returns true if the files are +// identical, false if they differ. +//////////////////////////////////////////////////////////////////// +bool CVSCopy:: +verify_binary_file(Filename source, Filename dest) { + source.set_binary(); + dest.set_binary(); + + ifstream s, d; + if (!source.open_read(s)) { + return false; + } + if (!dest.open_read(d)) { + return false; + } + + int cs, cd; + cs = s.get(); + cd = d.get(); + while (!s.eof() && !s.fail() && !d.eof() && !d.fail()) { + if (cs != cd) { + return false; + } + cs = s.get(); + cd = d.get(); + } + + if (s.fail() || d.fail()) { + // If we had some read error, call the files different. + return false; + } + + // If we haven't reached the end of one of the files yet, that file + // is longer than the other one, and the files are therefore + // different. + if (!s.eof() || !d.eof()) { + return false; + } + + // Otherwise, the files are the same. + return true; +} + //////////////////////////////////////////////////////////////////// // Function: CVSCopy::copy_binary_file // Access: Protected diff --git a/pandatool/src/cvscopy/cvsCopy.h b/pandatool/src/cvscopy/cvsCopy.h index 0a3b4caa70..2b53a394ff 100644 --- a/pandatool/src/cvscopy/cvsCopy.h +++ b/pandatool/src/cvscopy/cvsCopy.h @@ -32,10 +32,14 @@ protected: virtual bool handle_args(Args &args); virtual bool post_command_line(); + virtual bool verify_file(const Filename &source, const Filename &dest, + CVSSourceDirectory *dest_dir, + void *extra_data); virtual bool copy_file(const Filename &source, const Filename &dest, CVSSourceDirectory *dest_dir, void *extra_data, bool new_file)=0; + bool verify_binary_file(Filename source, Filename dest); bool copy_binary_file(Filename source, Filename dest); bool create_file(const Filename &filename); diff --git a/pandatool/src/cvscopy/cvsSourceTree.cxx b/pandatool/src/cvscopy/cvsSourceTree.cxx index da3b7f365c..5e13273687 100644 --- a/pandatool/src/cvscopy/cvsSourceTree.cxx +++ b/pandatool/src/cvscopy/cvsSourceTree.cxx @@ -396,8 +396,8 @@ ask_existing(const string &filename, const CVSSourceTree::Directories &dirs, CVSSourceDirectory *CVSSourceTree:: ask_new(const string &filename, CVSSourceDirectory *dir) { while (true) { - nout << filename << " will be created at " - << dir->get_path() + "/" + filename << ".\n"; + nout << filename << " will be created in " + << dir->get_path() << ".\n"; string result = prompt("Create this file (y/n)? "); nassertr(!result.empty(), (CVSSourceDirectory *)NULL); if (result.size() == 1) { diff --git a/pandatool/src/egg-palettize/eggPalettize.cxx b/pandatool/src/egg-palettize/eggPalettize.cxx index 0d7dc4ee20..73cd50e293 100644 --- a/pandatool/src/egg-palettize/eggPalettize.cxx +++ b/pandatool/src/egg-palettize/eggPalettize.cxx @@ -143,6 +143,13 @@ EggPalettize() : EggMultiFilter(true) { "which is an integer power of 2. They will be scaled down to " "achieve this.", &EggPalettize::dispatch_none, &_got_force_power_2); + add_option + ("nolock", "", 0, + "Don't attempt to lock the .pi file before rewriting it. Use " + "with extreme caution, as multiple processes running on the same " + ".pi file may overwrite each other. Use this only if the lock " + "cannot be achieved for some reason.", + &EggPalettize::dispatch_none, &_dont_lock_pi); add_option ("k", "", 0, "Kill lines from the attributes file that aren't used on any " @@ -555,7 +562,7 @@ run() { af.set_default_group(group); } - if (!af.grab_lock()) { + if (!_dont_lock_pi && !af.grab_lock()) { // Failing to grab the write lock on the attribute file is a // fatal error. exit(1); diff --git a/pandatool/src/egg-palettize/eggPalettize.h b/pandatool/src/egg-palettize/eggPalettize.h index dc81143be5..b386d18e2c 100644 --- a/pandatool/src/egg-palettize/eggPalettize.h +++ b/pandatool/src/egg-palettize/eggPalettize.h @@ -66,6 +66,7 @@ public: bool _optimal_resize; bool _touch_eggs; bool _eggs_include_images; + bool _dont_lock_pi; bool _remove_unused_lines; bool _describe_input_file; diff --git a/pandatool/src/fltprogs/fltCopy.cxx b/pandatool/src/fltprogs/fltCopy.cxx index cb6b105a1b..6a46c96deb 100644 --- a/pandatool/src/fltprogs/fltCopy.cxx +++ b/pandatool/src/fltprogs/fltCopy.cxx @@ -68,7 +68,7 @@ run() { //////////////////////////////////////////////////////////////////// // Function: FltCopy::copy_file // Access: Protected, Virtual -// Description: Called by import() if the timestamps indicate that a +// Description: Called by import() if verify_file() indicates that a // file needs to be copied. This does the actual copy // of a file from source to destination. If new_file is // true, then dest does not already exist.