diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-04-19 01:31:34 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-04-25 21:25:33 +0100 |
commit | e566d183c5ed3ed9b1b50c65226dc03a732ffcca (patch) | |
tree | c6213c7c4166b2c74316f745ee42fd4cd44766f6 | |
parent | Add a swaith of utility classes (diff) | |
download | gentoobrowse-api-e566d183c5ed3ed9b1b50c65226dc03a732ffcca.tar.bz2 gentoobrowse-api-e566d183c5ed3ed9b1b50c65226dc03a732ffcca.tar.xz gentoobrowse-api-e566d183c5ed3ed9b1b50c65226dc03a732ffcca.zip |
No more messy piping off a find process
-rw-r--r-- | gentoobrowse-api/service/maintenanceimpl.cpp | 21 | ||||
-rw-r--r-- | gentoobrowse-api/service/maintenanceimpl.h | 3 |
2 files changed, 10 insertions, 14 deletions
diff --git a/gentoobrowse-api/service/maintenanceimpl.cpp b/gentoobrowse-api/service/maintenanceimpl.cpp index eddf2b2..3e8f8f9 100644 --- a/gentoobrowse-api/service/maintenanceimpl.cpp +++ b/gentoobrowse-api/service/maintenanceimpl.cpp @@ -13,14 +13,6 @@ namespace Gentoo { { } - FilePtr - Maintenance::findInPath(const std::string & p) - { - AdHoc::Buffer find; - find.appendbf("(cd %s && find * -type f -printf \"%%p\t%%s\t%%TFT%%TT\\n\" -follow)", p); - return FilePtr(popen(find, "r"), pclose); - } - static void fileDeleted(DB::Connection * dbc, const boost::filesystem::path &, DB::SelectCommandPtr s) @@ -60,9 +52,16 @@ namespace Gentoo { boost::filesystem::create_symlink(p, tmp / n); }); dbc->execute(sql::maintenance::createTempFileListTable::sql); - dbc->beginBulkUpload("filelist", ""); - dbc->bulkUploadData(findInPath(tmp.string()).get()); - dbc->endBulkUpload(nullptr); + auto i = dbc->modify("INSERT INTO filelist(filename, filesize, filemtime) VALUES(?, ?, ?)"); + for (boost::filesystem::recursive_directory_iterator d(tmp, boost::filesystem::symlink_option::recurse); + d != boost::filesystem::recursive_directory_iterator(); d++) { + if (boost::filesystem::is_regular_file(d->status())) { + i->bindParamS(0, d->path().lexically_relative(tmp).string()); + i->bindParamI(1, boost::filesystem::file_size(*d)); + i->bindParamT(2, boost::posix_time::from_time_t(boost::filesystem::last_write_time(*d))); + i->execute(); + } + } dbc->execute(sql::maintenance::createTempFileListView::sql); } diff --git a/gentoobrowse-api/service/maintenanceimpl.h b/gentoobrowse-api/service/maintenanceimpl.h index c5ad6b7..19b2872 100644 --- a/gentoobrowse-api/service/maintenanceimpl.h +++ b/gentoobrowse-api/service/maintenanceimpl.h @@ -6,8 +6,6 @@ #include <abstractDatabaseClient.h> namespace Gentoo { - typedef boost::shared_ptr<FILE> FilePtr; - namespace Service { class DLL_PUBLIC Maintenance : public Gentoo::Maintenance, IceTray::AbstractDatabaseClient { public: @@ -18,7 +16,6 @@ namespace Gentoo { private: static void createTempFileList(DB::Connection *, const boost::filesystem::path &); static void processChanges(DB::Connection *, const boost::filesystem::path &); - static FilePtr findInPath(const std::string &); }; } } |