From e566d183c5ed3ed9b1b50c65226dc03a732ffcca Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 19 Apr 2016 01:31:34 +0100 Subject: No more messy piping off a find process --- gentoobrowse-api/service/maintenanceimpl.cpp | 21 ++++++++++----------- 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 namespace Gentoo { - typedef boost::shared_ptr 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 &); }; } } -- cgit v1.2.3