Changeset 159
- Timestamp:
- Aug 14, 2006, 9:39:49 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/svndigest.cc
r149 r159 13 13 svndigest is distributed in the hope that it will be useful, but 14 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 16 General Public License for more details. 17 17 … … 37 37 #include <unistd.h> 38 38 39 using namespace std; 39 /// 40 /// @brief Check whether \a path already exists or not. 41 /// 42 /// @return True if \a path exists, false otherwise. 43 /// 44 bool check_target(const std::string& path) 45 { 46 struct stat buf; 47 return !stat(path.c_str(),&buf); 48 } 49 40 50 41 51 int main(const int argc,const char* argv[]) … … 62 72 } 63 73 74 // check if target already exists and behave appropriately 75 std::string target_path=option->targetdir() + '/' + file_name(option->root()); 76 bool need_to_erase_target = check_target(target_path); 77 if (need_to_erase_target && !option->force()) 78 throw std::runtime_error(std::string("svndigest: directory (") + 79 target_path + ") already exists"); 80 64 81 // Extract repository location 65 82 std::string repo; … … 74 91 } 75 92 93 // build directory tree already here ... if WC is upto date with 94 // repo an exception is thrown. This avoids several costly 95 // statements below and will not remove a digest tree below if a 96 // tree already exists. 97 Directory tree(0,option->root(),""); 98 tree.parse(option->verbose()); 99 76 100 // Retrieve commit dates. 77 101 std::vector<std::string> commit_dates; … … 85 109 } 86 110 87 // check if target already exists and behave appropriately 88 std::string root_path(option->targetdir()+'/'+file_name(option->root())); 89 struct stat buf; 90 if (!stat(root_path.c_str(),&buf)) 91 // root_path already exists 92 if (option->force()) { 93 // force true -> removal of root_path 111 // remove target if needed 112 if (need_to_erase_target) { 94 113 if (option->verbose()) 95 std::cout << "rm -rf " << root_path << "\n"; 96 rmdirhier(root_path); 97 } 98 else { 99 // force false -> exit 100 std::cerr << "\nsvndigest: " << root_path << ": directory already exists" 101 << std::endl; 102 exit(-1); 103 } 114 std::cout << "rm -rf " << target_path << "\n"; 115 rmdirhier(target_path); 116 } 104 117 105 118 if (!option->revisions()) 106 119 GnuplotFE::instance()->set_dates(commit_dates); 107 108 Directory tree(0,option->root(),""); 109 tree.parse(option->verbose()); 110 111 GnuplotFE::instance()->command(string("cd '")+option->targetdir()+"'"); 120 GnuplotFE::instance()->command(std::string("cd '")+option->targetdir()+"'"); 112 121 chdir(option->targetdir().c_str()); 113 122 try { … … 125 134 exit(0); // normal exit 126 135 } 127 128
Note: See TracChangeset
for help on using the changeset viewer.