From 84becc3b35fffa68928bb20ff088ba5c7fc9a927 Mon Sep 17 00:00:00 2001 From: Martin Raiber Date: Fri, 6 May 2011 18:08:14 +0200 Subject: [PATCH] Added glob file exclusion --- urbackup/ClientService.cpp | 32 +++++-- urbackup/ClientService.h | 2 +- urbackup/clientdao.cpp | 2 +- urbackup/clientdao.h | 2 +- urbackup/glob/glob.cpp | 145 ++++++++++++++++++++++++++++++ urbackup/server_get.cpp | 10 +-- urbackup/urbackup.vcxproj | 1 + urbackup/urbackup.vcxproj.filters | 6 ++ 8 files changed, 185 insertions(+), 15 deletions(-) create mode 100644 urbackup/glob/glob.cpp diff --git a/urbackup/ClientService.cpp b/urbackup/ClientService.cpp index 6fcf7814..f0a41c29 100644 --- a/urbackup/ClientService.cpp +++ b/urbackup/ClientService.cpp @@ -159,6 +159,9 @@ bool ClientConnector::Run(void) do_quit=true; return true; } + IScopedLock lock(backup_mutex); + backup_running=0; + backup_done=true; return false; } else if(msg=="done") @@ -172,6 +175,9 @@ bool ClientConnector::Run(void) tcpstack.Send(pipe, msg); lasttime=Server->getTimeMS(); state=0; + IScopedLock lock(backup_mutex); + backup_running=0; + backup_done=true; } }break; case 2: @@ -645,6 +651,11 @@ void ClientConnector::ReceivePackets(void) Server->Log("Invalid command", LL_ERROR); } } + else if(cmd.find("1GET BACKUP DIRS")==0 && pw_ok==true) + { + getBackupDirs(1); + lasttime=Server->getTimeMS(); + } else if(cmd.find("GET BACKUP DIRS")==0 && pw_ok==true) { getBackupDirs(); @@ -1212,15 +1223,19 @@ bool ClientConnector::checkPassword(const std::wstring &pw) return stored_pw==Server->ConvertToUTF8(pw); } -void ClientConnector::getBackupDirs(void) +void ClientConnector::getBackupDirs(int version) { IDatabase *db=Server->getDatabase(Server->getThreadID(), URBACKUPDB_CLIENT); - IQuery *q=db->Prepare("SELECT id,path FROM backupdirs"); + IQuery *q=db->Prepare("SELECT id,name,path FROM backupdirs"); db_results res=q->Read(); std::string msg; for(size_t i=0;iConvertToUTF8(res[i][L"id"])+"\n"; + if(version!=0) + { + msg+=Server->ConvertToUTF8(res[i][L"name"])+"|"; + } msg+=Server->ConvertToUTF8(res[i][L"path"]); if(i+1second.empty()) + name=name_arg->second; + else + name=widen(replaceChars( ExtractFileName(wnarrow(dir) ) )); if(dir[dir.size()-1]=='\\' || dir[dir.size()-1]=='/' ) dir.erase(dir.size()-1,1); @@ -1258,10 +1276,10 @@ bool ClientConnector::saveBackupDirs(str_map &args) for(int k=0;k<100;++k) { q2->Reset(); - q2->Bind(name+"_"+nconvert(k)); + q2->Bind(name+L"_"+convert(k)); if(q2->Read().empty()==true) { - name+="_"+nconvert(k); + name+=L"_"+convert(k); break; } } diff --git a/urbackup/ClientService.h b/urbackup/ClientService.h index 7a1fdd0b..d8d9a79f 100644 --- a/urbackup/ClientService.h +++ b/urbackup/ClientService.h @@ -28,7 +28,7 @@ public: private: bool checkPassword(const std::wstring &cmd); - void getBackupDirs(void); + void getBackupDirs(int version=0); bool saveBackupDirs(str_map &args); void updateLastBackup(void); void getBackupStatus(void); diff --git a/urbackup/clientdao.cpp b/urbackup/clientdao.cpp index 8da08314..97e06b69 100644 --- a/urbackup/clientdao.cpp +++ b/urbackup/clientdao.cpp @@ -208,7 +208,7 @@ std::vector ClientDAO::getBackupDirs(void) { SBackupDir dir; dir.id=watoi(res[i][L"id"]); - dir.tname=wnarrow(res[i][L"name"]); + dir.tname=res[i][L"name"]; dir.path=res[i][L"path"]; ret.push_back(dir); diff --git a/urbackup/clientdao.h b/urbackup/clientdao.h index 2171bdc8..fb7e8058 100644 --- a/urbackup/clientdao.h +++ b/urbackup/clientdao.h @@ -25,7 +25,7 @@ typedef struct _GUID { struct SBackupDir { int id; - std::string tname; + std::wstring tname; std::wstring path; }; diff --git a/urbackup/glob/glob.cpp b/urbackup/glob/glob.cpp new file mode 100644 index 00000000..a3233dac --- /dev/null +++ b/urbackup/glob/glob.cpp @@ -0,0 +1,145 @@ +/* + * robust glob pattern matcher + * ozan s. yigit/dec 1994 + * public domain + * + * glob patterns: + * * matches zero or more wchar_tacters + * ? matches any single wchar_tacter + * [set] matches any wchar_tacter in the set + * [^set] matches any wchar_tacter NOT in the set + * where a set is a group of wchar_tacters or ranges. a range + * is written as two wchar_tacters seperated with a hyphen: a-z denotes + * all wchar_tacters between a to z inclusive. + * [-set] set matches a literal hypen and any wchar_tacter in the set + * []set] matches a literal close bracket and any wchar_tacter in the set + * + * char matches itself except where char is '*' or '?' or '[' + * \char matches char, including any pattern wchar_tacter + * + * examples: + * a*c ac abc abbc ... + * a?c acc abc aXc ... + * a[a-z]c aac abc acc ... + * a[-a-z]c a-c aac abc ... + * + * $Log: glob.c,v $ + * Revision 1.3 1995/09/14 23:24:23 oz + * removed boring test/main code. + * + * Revision 1.2 94/12/11 10:38:15 oz + * cset code fixed. it is now robust and interprets all + * variations of cset [i think] correctly, including [z-a] etc. + * + * Revision 1.1 94/12/08 12:45:23 oz + * Initial revision + */ + +#ifndef NEGATE +#define NEGATE '^' /* std cset negation char */ +#endif + +bool amatch(const wchar_t *str, const wchar_t *p) +{ + int negate; + int match; + int c; + + while (*p) { + if (!*str && *p != '*') + return false; + + switch (c = *p++) { + + case '*': + while (*p == '*') + p++; + + if (!*p) + return true; + + if (*p != '?' && *p != '[' && *p != '\\') + while (*str && *p != *str) + str++; + + while (*str) { + if (amatch(str, p)) + return true; + str++; + } + return false; + + case '?': + if (*str) + break; + return false; +/* + * set specification is inclusive, that is [a-z] is a, z and + * everything in between. this means [z-a] may be interpreted + * as a set that contains z, a and nothing in between. + */ + case '[': + if (*p != NEGATE) + negate = false; + else { + negate = true; + p++; + } + + match = false; + + while (!match && (c = *p++)) { + if (!*p) + return false; + if (*p == '-') { /* c-c */ + if (!*++p) + return false; + if (*p != ']') { + if (*str == c || *str == *p || + (*str > c && *str < *p)) + match = true; + } + else { /* c-] */ + if (*str >= c) + match = true; + break; + } + } + else { /* cc or c] */ + if (c == *str) + match = true; + if (*p != ']') { + if (*p == *str) + match = true; + } + else + break; + } + } + + if (negate == match) + return false; +/* + * if there is a match, skip past the cset and continue on + */ + while (*p && *p != ']') + p++; + if (!*p++) /* oops! */ + return false; + break; + + case '\\': + if (*p) + c = *p++; + default: + if (c != *str) + return false; + break; + + } + str++; + } + + return !*str; +} + diff --git a/urbackup/server_get.cpp b/urbackup/server_get.cpp index 40a5b3bc..6e853a7f 100644 --- a/urbackup/server_get.cpp +++ b/urbackup/server_get.cpp @@ -809,7 +809,7 @@ bool BackupServerGet::request_filelist_construct(bool full) delete [] pck; if(ret!="DONE") { - ServerLogger::Log(clientid, "Constructing of filelist of \""+clientname+"\" failed - TIMEOUT(2)", LL_ERROR); + ServerLogger::Log(clientid, "Constructing of filelist of \""+clientname+"\" failed: "+ret, LL_ERROR); break; } else @@ -930,7 +930,7 @@ bool BackupServerGet::doFullBackup(void) std::wstring t=curr_path; t.erase(0,1); ServerLogger::Log(clientid, L"Starting shadowcopy \""+t+L"\".", LL_INFO); - start_shadowcopy(wnarrow(t)); + start_shadowcopy(Server->ConvertToUTF8(t)); } } else @@ -941,7 +941,7 @@ bool BackupServerGet::doFullBackup(void) std::wstring t=curr_path; t.erase(0,1); ServerLogger::Log(clientid, L"Stoping shadowcopy \""+t+L"\".", LL_INFO); - stop_shadowcopy(wnarrow(t)); + stop_shadowcopy(Server->ConvertToUTF8(t)); } curr_path=ExtractFilePath(curr_path); } @@ -1279,7 +1279,7 @@ bool BackupServerGet::doIncrBackup(void) t.erase(0,1); if(r_offline==false) { - start_shadowcopy(wnarrow(t)); + start_shadowcopy(Server->ConvertToUTF8(t)); } } } @@ -1296,7 +1296,7 @@ bool BackupServerGet::doIncrBackup(void) t.erase(0,1); if(r_offline==false) { - stop_shadowcopy(wnarrow(t)); + stop_shadowcopy(Server->ConvertToUTF8(t)); } } curr_path=ExtractFilePath(curr_path); diff --git a/urbackup/urbackup.vcxproj b/urbackup/urbackup.vcxproj index 8c8eaf8c..83b31925 100644 --- a/urbackup/urbackup.vcxproj +++ b/urbackup/urbackup.vcxproj @@ -596,6 +596,7 @@ + diff --git a/urbackup/urbackup.vcxproj.filters b/urbackup/urbackup.vcxproj.filters index 8d9cc66f..d2e6b027 100644 --- a/urbackup/urbackup.vcxproj.filters +++ b/urbackup/urbackup.vcxproj.filters @@ -28,6 +28,9 @@ {1e3a9954-74c9-4bbf-b99c-4f78b6bd555f} + + {a6950ae3-9a5d-43aa-a26a-f3429f1cfb83} + @@ -195,6 +198,9 @@ treediff + + glob +