From b7e21e1584579db219d9a1f3290b51e76eda4beb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 31 Jan 2016 17:26:17 +0000 Subject: Add by date folder --- mythfs/service/inodes/filterByDateDirectory.cpp | 44 +++++++++++++++++++++++ mythfs/service/inodes/filterByDateDirectory.h | 24 +++++++++++++ mythfs/service/inodes/groupingByDateDirectory.cpp | 23 ++++++++++++ mythfs/service/inodes/groupingByDateDirectory.h | 9 +++-- mythfs/service/recordingsVolume.cpp | 2 ++ mythfs/unittests/testMain.cpp | 39 ++++++++++++++++++-- 6 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 mythfs/service/inodes/filterByDateDirectory.cpp create mode 100644 mythfs/service/inodes/filterByDateDirectory.h create mode 100644 mythfs/service/inodes/groupingByDateDirectory.cpp diff --git a/mythfs/service/inodes/filterByDateDirectory.cpp b/mythfs/service/inodes/filterByDateDirectory.cpp new file mode 100644 index 0000000..ddf048c --- /dev/null +++ b/mythfs/service/inodes/filterByDateDirectory.cpp @@ -0,0 +1,44 @@ +#include "filterByDateDirectory.h" +#include "symlink.h" +#include +#include +#include + +namespace MythFS { + FilterByDateDirectory::FilterByDateDirectory(DBPrx db, const std::string & d) : + FilteringDirectory(db), + date(d) + { + } + + std::string + FilterByDateDirectory::attribute(const MythFS::RecordedPtr & r) const + { + AdHoc::Buffer n; + n.append(r->title); + if (!r->subtitle.empty()) { + n.appendbf(": %s", r->subtitle); + } + n.append(".mpg"); + return n; + } + + Node::PointerType + FilterByDateDirectory::getChild(const std::string & n) const + { + for (auto r :db->getRecorded()) { + if (attribute(r) == n) { + return new Symlink("/var/store/mythrecordings/" + r->basename); + } + } + throw NetFS::SystemError(ENOENT); + } + + bool + FilterByDateDirectory::matches(const MythFS::RecordedPtr & r) const + { + return boost::algorithm::starts_with(r->startTime, date); + } +} + + diff --git a/mythfs/service/inodes/filterByDateDirectory.h b/mythfs/service/inodes/filterByDateDirectory.h new file mode 100644 index 0000000..84da471 --- /dev/null +++ b/mythfs/service/inodes/filterByDateDirectory.h @@ -0,0 +1,24 @@ +#ifndef MYTHFS_FILTERBYDATE_H +#define MYTHFS_FILTERBYDATE_H + +#include "filteringDirectory.h" +#include +#include + +namespace MythFS { + class FilterByDateDirectory : public FilteringDirectory { + public: + FilterByDateDirectory(DBPrx db, const std::string &); + + protected: + std::string attribute(const MythFS::RecordedPtr &) const; + bool matches(const MythFS::RecordedPtr &) const; + PointerType getChild(const std::string &) const; + + const std::string date; + }; +} + +#endif + + diff --git a/mythfs/service/inodes/groupingByDateDirectory.cpp b/mythfs/service/inodes/groupingByDateDirectory.cpp new file mode 100644 index 0000000..dccf38e --- /dev/null +++ b/mythfs/service/inodes/groupingByDateDirectory.cpp @@ -0,0 +1,23 @@ +#include "groupingByDateDirectory.h" +#include "filterByDateDirectory.h" + +namespace MythFS { + ByDateDirectory::ByDateDirectory(DBPrx db) : + GroupingDirectory(db) + { + } + + std::string + ByDateDirectory::attribute(const MythFS::RecordedPtr & r) const + { + return r->startTime.substr(0, 10); + } + + Node::PointerType + ByDateDirectory::getChild(const std::string & t) const + { + return new FilterByDateDirectory(db, t); + } +} + + diff --git a/mythfs/service/inodes/groupingByDateDirectory.h b/mythfs/service/inodes/groupingByDateDirectory.h index 945a9d0..1fef9e5 100644 --- a/mythfs/service/inodes/groupingByDateDirectory.h +++ b/mythfs/service/inodes/groupingByDateDirectory.h @@ -1,13 +1,16 @@ -#ifndef MYTHFS_BYTITLEDIRECTORY_H -#define MYTHFS_BYTITLEDIRECTORY_H +#ifndef MYTHFS_BYDATEDIRECTORY_H +#define MYTHFS_BYDATEDIRECTORY_H #include "groupingDirectory.h" namespace MythFS { class ByDateDirectory : public GroupingDirectory { + public: + ByDateDirectory(DBPrx db); protected: - virtual std::string attribute(const MythFS::RecordedPtr &) const; + std::string attribute(const MythFS::RecordedPtr &) const override; + PointerType getChild(const std::string &) const override; }; } diff --git a/mythfs/service/recordingsVolume.cpp b/mythfs/service/recordingsVolume.cpp index 18d837c..ff29787 100644 --- a/mythfs/service/recordingsVolume.cpp +++ b/mythfs/service/recordingsVolume.cpp @@ -5,6 +5,7 @@ #include #include "inodes/allDirectory.h" #include "inodes/groupingByTitleDirectory.h" +#include "inodes/groupingByDateDirectory.h" #include "openDirectory.h" #include #include @@ -14,6 +15,7 @@ namespace MythFS { { contents.insert({ "all", new AllDirectory(db) }); contents.insert({ "by title", new ByTitleDirectory(db) }); + contents.insert({ "by date", new ByDateDirectory(db) }); } NetFS::DirectoryPrx diff --git a/mythfs/unittests/testMain.cpp b/mythfs/unittests/testMain.cpp index 6ddafe0..3fda87d 100644 --- a/mythfs/unittests/testMain.cpp +++ b/mythfs/unittests/testMain.cpp @@ -69,9 +69,10 @@ BOOST_AUTO_TEST_CASE( listRoot ) { auto d = rv->opendir(re, "/"); auto ls = d->readdir(); - BOOST_REQUIRE_EQUAL(2, ls.size()); + BOOST_REQUIRE_EQUAL(3, ls.size()); BOOST_REQUIRE_EQUAL("all", ls[0]); - BOOST_REQUIRE_EQUAL("by title", ls[1]); + BOOST_REQUIRE_EQUAL("by date", ls[1]); + BOOST_REQUIRE_EQUAL("by title", ls[2]); d->close(); } @@ -103,6 +104,12 @@ BOOST_AUTO_TEST_CASE( statByTitle ) BOOST_REQUIRE(S_ISDIR(a.mode)); } +BOOST_AUTO_TEST_CASE( statByDate ) +{ + auto a = rv->getattr(re, "/by date"); + BOOST_REQUIRE(S_ISDIR(a.mode)); +} + BOOST_AUTO_TEST_CASE( listByTitle ) { auto d = rv->opendir(re, "/by title"); @@ -130,6 +137,34 @@ BOOST_AUTO_TEST_CASE( listByTitleInsidious ) BOOST_REQUIRE_EQUAL("/var/store/mythrecordings/1303_20151202205900.mpg", l); } +BOOST_AUTO_TEST_CASE( listByDate ) +{ + auto d = rv->opendir(re, "/by date"); + auto ls = d->readdir(); + BOOST_REQUIRE_EQUAL(9, ls.size()); + BOOST_REQUIRE_EQUAL("2015-12-20", ls.front()); + BOOST_REQUIRE_EQUAL("2015-12-02", ls.back()); + d->close(); + + auto a = rv->getattr(re, "/by date/2015-12-20"); + BOOST_REQUIRE(S_ISDIR(a.mode)); +} + +BOOST_AUTO_TEST_CASE( listByDate20151220 ) +{ + auto d = rv->opendir(re, "/by date/2015-12-20"); + auto ls = d->readdir(); + BOOST_REQUIRE_EQUAL(2, ls.size()); + BOOST_REQUIRE_EQUAL("Have I Got a Bit More News for You.mpg", ls.front()); + BOOST_REQUIRE_EQUAL("Live at the Apollo: Part 0: Christmas Special.mpg", ls.back()); + d->close(); + + auto a = rv->getattr(re, "/by date/2015-12-20/Have I Got a Bit More News for You.mpg"); + BOOST_REQUIRE(S_ISLNK(a.mode)); + auto l = rv->readlink(re, "/by date/2015-12-20/Have I Got a Bit More News for You.mpg"); + BOOST_REQUIRE_EQUAL("/var/store/mythrecordings/1001_20151220233900.mpg", l); +} + BOOST_AUTO_TEST_CASE( statfs ) { rv->statfs(re, "/"); -- cgit v1.2.3