From 6ef5f24fd2e7a5fc897019a84403f583f5df79bb Mon Sep 17 00:00:00 2001 From: Phitherek Date: Sun, 30 Sep 2012 23:53:06 +0200 Subject: [PATCH] started to write -R, now compiles, but segfaults --- 3m.cpp | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/3m.cpp b/3m.cpp index ea26f02..fc0f8a1 100644 --- a/3m.cpp +++ b/3m.cpp @@ -1,8 +1,10 @@ #include #include +#include #include // For sockets #include // For getaddrinfo #include // For mkdir etc. +#include #include // For inet addr conversion #include // For getaddrinfo #include // For memset @@ -1194,6 +1196,63 @@ int checkdeps(int lmodlistidx, vector lmodlist, vector 2) { + if(n == 3) { + int ret = chdir(dirname.c_str()); + if(ret == -1) { + cerr << "Could not chdir: " << strerror(errno) << endl; + return 1; + } + } + int ret = recursive_rmdir(d -> d_name); + if(ret == 1) { + cerr << "recursive_rmdir failed!" << endl; + return 1; + } + } + } + if(n > 2) { + int ret = chdir(".."); + if(ret == -1) { + cerr << "Could not chdir: " << strerror(errno) << endl; + return 1; + } + closedir(dir); + ret = rmdir(dirname.c_str()); + if(ret == -1) { + cerr << "Could not rmdir: " << strerror(errno) << endl; + return 1; + } + return 0; + } +} +} + int main(int argc, char **argv) { homedir = getenv("HOME"); string config, modlistsfn; @@ -1676,6 +1735,66 @@ if(argv[1][1] == 'S') { ri.close(); cout << "Installation finished successfully!" << endl; } +} else if(argv[1][1] == 'R') { + if(argc < 3) { + cerr << "You must enter at least one mod name! Exiting..." << endl; + return EXIT_FAILURE; + } + int eri = 0; + vector repoinfo; + int ripr; + ripr = parserepoinfo(&repoinfo, localri); + if(ripr == 1) { + cerr << "Local repoinfo parse error! Exiting..." << endl; + return EXIT_FAILURE; + } + for(int i = 2; i < argc; i++) { + int ridx = -1; + for(int j = 0; j < repoinfo.size(); j++) { + if(strip_endl(repoinfo[j].name) == strip_endl(argv[i])) { + ridx = j; + } + } + if(ridx == -1) { + cerr << "Mod " << argv[i] << " not found in local repository! Skipping..." << endl; + } else { + int ret = chdir(localrepo.c_str()); + if(ret == -1) { + cerr << "Could not chdir to local repository: " << errno << endl; + return EXIT_FAILURE; + } + ret = recursive_rmdir(repoinfo[ridx].name.c_str()); + if(ret == 1) { + cerr << "Error in recursive_rmdir for " << argv[i] << "! Skipping..." << endl; + } else { + vector::iterator it; + int k; + for(it = repoinfo.begin(), k = 0; it < repoinfo.end() && k <= ridx; k++, it++); + it = repoinfo.erase(it); + if(it == repoinfo.end()) { + eri = 1; + ret = unlink(localri.c_str()); + if(ret == -1) { + cerr << "Could not delete empty repoinfo file: " << strerror(errno) << endl; + return EXIT_FAILURE; + } + } + cout << argv[i] << " successfully removed!" << endl; + } + } +} +if(eri == 0) { +ofstream ri(localri.c_str()); + if(!ri) { + cerr << "Could not open local repoinfo file for writing!" << endl; + return EXIT_FAILURE; + } + for(int k = 0; k < repoinfo.size(); k++) { + ri << '{' << strip_endl(repoinfo[k].name) << '}' << endl << "[release]" << endl << repoinfo[k].release << endl << "[path]" << endl << strip_endl(repoinfo[k].path) << endl << "{end}" << endl; + } + ri.close(); +} + cout << "Removal finished successfully!" << endl; } else { cout << "No such action: " << argv[1] << endl << "Usage: " << argv[0] << " [-S/I/U/R/Q/h/v] [options] arg1 arg2 ..." << endl; }