Prevent C and Python clients from uploading .pbl, .bak and ~ files.

This commit is contained in:
Eric S. Raymond 2007-11-08 17:23:11 +00:00
parent cfa93a03a1
commit 1920174d39
4 changed files with 7 additions and 1 deletions

View file

@ -314,6 +314,8 @@ class CampaignClient:
for fn in glob.glob(path + "/*"):
if os.path.isdir(fn):
sub = put_dir(os.path.basename(fn), fn)
elif fn.endswith("~") or fn.endswith(".bak") or ".pbl" in fn:
continue
else:
sub = put_file(os.path.basename(fn), file(fn))
data.insert(sub)

View file

@ -298,7 +298,7 @@ namespace {
#include <CoreFoundation/CFBase.h>
#endif
static bool ends_with(const std::string& str, const std::string& suffix)
bool ends_with(const std::string& str, const std::string& suffix)
{
return str.size() >= suffix.size() && std::equal(suffix.begin(),suffix.end(),str.end()-suffix.size());
}

View file

@ -108,6 +108,8 @@ const file_tree_checksum& data_tree_checksum();
//! Returns the size of a file, or -1 if the file doesn't exist.
int file_size(const std::string& fname);
bool ends_with(const std::string& str, const std::string& suffix);
//! Returns the base filename of a file, with directory name stripped.
//! Equivalent to a portable basename() function.
std::string file_name(const std::string& file);

View file

@ -181,6 +181,8 @@ static void archive_dir(const std::string& path, const std::string& dirname, con
std::vector<std::string> files, dirs;
get_files_in_dir(dir,&files,&dirs);
for(std::vector<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
if (ends_with(*i, "~")||ends_with(*i, "-bak")||(*i).find(".pbl")!=std::string::npos)
continue;
archive_file(dir,*i,cfg.add_child("file"));
}