diff options
Diffstat (limited to 'ept/debtags/maint')
-rw-r--r-- | ept/debtags/maint/path.cc | 113 | ||||
-rw-r--r-- | ept/debtags/maint/path.h | 125 | ||||
-rw-r--r-- | ept/debtags/maint/sourcedir.cc | 141 | ||||
-rw-r--r-- | ept/debtags/maint/sourcedir.h | 75 | ||||
-rw-r--r-- | ept/debtags/maint/sourcedir.tcc | 55 |
5 files changed, 0 insertions, 509 deletions
diff --git a/ept/debtags/maint/path.cc b/ept/debtags/maint/path.cc deleted file mode 100644 index bb08682..0000000 --- a/ept/debtags/maint/path.cc +++ /dev/null @@ -1,113 +0,0 @@ -// -*- mode: c++; indent-tabs-mode: t -*- - -/** \file - * debtags paths - */ - -/* - * Copyright (C) 2005,2006,2007 Enrico Zini <enrico@debian.org>, Peter Rockai <me@mornfall.net> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <ept/debtags/maint/path.h> -#include <ept/config.h> - -#include <wibble/sys/fs.h> -#include <wibble/string.h> - -#include <sys/types.h> // getpwuid, getuid -#include <pwd.h> // getpwuid -#include <unistd.h> // getuid - -using namespace wibble; - -namespace ept { -namespace debtags { - -static std::string userdir() -{ - std::string rcdir; - - struct passwd* udata = getpwuid(getuid()); - rcdir = str::joinpath(udata->pw_dir, ".debtags"); - - return rcdir; -} - - -Path &Path::instance() { - if (!s_instance) { - s_instance = new Path; - instance().m_debtagsSourceDir = DEBTAGS_DB_DIR; - instance().m_debtagsIndexDir = DEBTAGS_DB_DIR; - instance().m_debtagsUserSourceDir = userdir(); - instance().m_debtagsUserIndexDir = userdir(); - } - return *s_instance; -} - -int Path::access( const std::string &s, int m ) { - return ::access( s.c_str(), m ); -} - -time_t Path::timestamp( const std::string& file ) { - return sys::fs::timestamp(file, 0); -} - -void Path::setDebtagsSourceDir( const std::string &s ) -{ - instance().m_debtagsSourceDir = s; -} -void Path::setDebtagsIndexDir( const std::string &s ) -{ - instance().m_debtagsIndexDir = s; -} -void Path::setDebtagsUserSourceDir( const std::string &s ) -{ - instance().m_debtagsUserSourceDir = s; -} -void Path::setDebtagsUserIndexDir( const std::string &s ) -{ - instance().m_debtagsUserIndexDir = s; -} - -std::string Path::debtagsSourceDir() { return instance().m_debtagsSourceDir; } -std::string Path::debtagsIndexDir() { return instance().m_debtagsIndexDir; } -std::string Path::debtagsUserSourceDir() { return instance().m_debtagsUserSourceDir; } -std::string Path::debtagsUserIndexDir() { return instance().m_debtagsUserIndexDir; } - -std::string Path::vocabulary() { - return str::joinpath(debtagsIndexDir(), "vocabulary"); -} - -std::string Path::userVocabulary() { - return str::joinpath(debtagsUserIndexDir(), "vocabulary"); -} - -std::string Path::tagdb() { - return str::joinpath(debtagsIndexDir(), "package-tags"); -} - -std::string Path::userTagdb() { - return str::joinpath(debtagsUserIndexDir(), "package-tags"); -} - -Path *Path::s_instance = 0; - -} -} - -// vim:set ts=4 sw=4: diff --git a/ept/debtags/maint/path.h b/ept/debtags/maint/path.h deleted file mode 100644 index 2c7f95e..0000000 --- a/ept/debtags/maint/path.h +++ /dev/null @@ -1,125 +0,0 @@ -// -*- mode: c++; indent-tabs-mode: t -*- -/** \file - * debtags paths - */ - -/* - * Copyright (C) 2005,2006,2007 Enrico Zini <enrico@debian.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <string> - -#ifndef EPT_DEBTAGS_PATH_H -#define EPT_DEBTAGS_PATH_H - -namespace ept { -namespace debtags { - -/** - * Singleton class to configure and access the various Debtags paths - */ -class Path -{ -public: - static std::string vocabulary(); - static std::string userVocabulary(); - static std::string tagdb(); - static std::string userTagdb(); - - static std::string debtagsSourceDir(); - static std::string debtagsIndexDir(); - static std::string debtagsUserSourceDir(); - static std::string debtagsUserIndexDir(); - - // Directory where Debtags source data is found - static void setDebtagsSourceDir( const std::string &s ); - - // Directory where Debtags indexes are kept - static void setDebtagsIndexDir( const std::string &s ); - - // User-specific directory for Debtags source data - static void setDebtagsUserSourceDir( const std::string &s ); - - // User-specific directory for Debtags index data - static void setDebtagsUserIndexDir( const std::string &s ); - - static int access( const std::string &, int ); - static time_t timestamp( const std::string& ); - - // RAII-style classes to temporarily override directories - class OverrideDebtagsSourceDir - { - std::string old; - public: - OverrideDebtagsSourceDir(const std::string& path) : old(Path::debtagsSourceDir()) - { - Path::setDebtagsSourceDir(path); - } - ~OverrideDebtagsSourceDir() { Path::setDebtagsSourceDir(old); } - }; - class OverrideDebtagsIndexDir - { - std::string old; - public: - OverrideDebtagsIndexDir(const std::string& path) : old(Path::debtagsIndexDir()) - { - Path::setDebtagsIndexDir(path); - } - ~OverrideDebtagsIndexDir() { Path::setDebtagsIndexDir(old); } - }; - class OverrideDebtagsUserSourceDir - { - std::string old; - public: - OverrideDebtagsUserSourceDir(const std::string& path) : old(Path::debtagsUserSourceDir()) - { - Path::setDebtagsUserSourceDir(path); - } - ~OverrideDebtagsUserSourceDir() { Path::setDebtagsUserSourceDir(old); } - }; - class OverrideDebtagsUserIndexDir - { - std::string old; - public: - OverrideDebtagsUserIndexDir(const std::string& path) : old(Path::debtagsUserIndexDir()) - { - Path::setDebtagsUserIndexDir(path); - } - ~OverrideDebtagsUserIndexDir() { Path::setDebtagsUserIndexDir(old); } - }; -protected: - static Path *s_instance; - static Path &instance(); - - // Directory where Debtags source data is found - std::string m_debtagsSourceDir; - - // Directory where Debtags indexes are kept - std::string m_debtagsIndexDir; - - // User-specific directory for Debtags source data - std::string m_debtagsUserSourceDir; - - // User-specific directory for Debtags index data - std::string m_debtagsUserIndexDir; -}; - -} -} - -// vim:set ts=4 sw=4: -#endif diff --git a/ept/debtags/maint/sourcedir.cc b/ept/debtags/maint/sourcedir.cc deleted file mode 100644 index 859455a..0000000 --- a/ept/debtags/maint/sourcedir.cc +++ /dev/null @@ -1,141 +0,0 @@ -#include <ept/debtags/maint/sourcedir.h> -#include <ept/debtags/vocabulary.h> -#include <ept/debtags/maint/path.h> - -#include <wibble/string.h> -#include <wibble/sys/fs.h> - -#include <tagcoll/input/zlib.h> -#include <tagcoll/input/stdio.h> - -using namespace std; -using namespace wibble; - -namespace ept { -namespace debtags { - -SourceDir::SourceDir(const std::string& path) - : sys::fs::Directory(path) -{ -} -SourceDir::~SourceDir() -{ -} - -SourceDir::FileType SourceDir::fileType(const std::string& name) -{ - if (name[0] == '.') return SKIP; - - // Filenames need to be at least 5 characters long (one char plus - // extension) - if (name.size() <= 4) return SKIP; - - if (name == "package-tags") return TAG; - if (name == "vocabulary") return VOC; - - // Only look at .voc and .tag files - std::string ext(name, name.size() - 4); - if (ext == ".voc") - return VOC; - if (ext == ".tag") - return TAG; - - // Now look for compressed files, which must have the 4 character extension - // plus the 3 chars of '.gz' - if (name.size() <= 7) return SKIP; - - ext = name.substr(name.size() - 7); - if (ext == ".voc.gz") - return VOCGZ; - if (ext == ".tag.gz") - return TAGGZ; - - return SKIP; -} - -time_t SourceDir::timestamp() -{ - if (!exists()) return 0; - - time_t max = 0; - for (const_iterator d = begin(); d != end(); ++d) - { - string name = *d; - FileType type = fileType(name); - if (type == SKIP) continue; - - time_t ts = Path::timestamp(str::joinpath(m_path, name)); - if (ts > max) max = ts; - } - - return max; -} - -time_t SourceDir::vocTimestamp() -{ - if (!exists()) return 0; - - time_t max = 0; - for (const_iterator d = begin(); d != end(); ++d) - { - string name = *d; - FileType type = fileType(name); - if (type != VOC and type != VOCGZ) continue; - - time_t ts = Path::timestamp(str::joinpath(m_path, name)); - if (ts > max) max = ts; - } - - return max; -} - -time_t SourceDir::tagTimestamp() -{ - if (!exists()) return 0; - - time_t max = 0; - for (const_iterator d = begin(); d != end(); ++d) - { - string name = *d; - FileType type = fileType(name); - if (type != TAG and type != TAGGZ) continue; - - time_t ts = Path::timestamp(str::joinpath(m_path, name)); - if (ts > max) max = ts; - } - - return max; -} - -void SourceDir::readVocabularies(Vocabulary& out) -{ - if (!exists()) return; - - for (const_iterator d = begin(); d != end(); ++d) - { - string name = *d; - if (name[0] == '.') continue; - FileType type = fileType(name); - if (type == VOC) - { - // Read uncompressed data - tagcoll::input::Stdio in(str::joinpath(m_path, name)); - - // Read the vocabulary - out.read(in); - } - else if (type == VOCGZ) - { - // Read compressed data - tagcoll::input::Zlib in(str::joinpath(m_path, name)); - - // Read the vocabulary - out.read(in); - } - } -} - -} -} - -// vim:set ts=4 sw=4: diff --git a/ept/debtags/maint/sourcedir.h b/ept/debtags/maint/sourcedir.h deleted file mode 100644 index 33d38e3..0000000 --- a/ept/debtags/maint/sourcedir.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef EPT_DEBTAGS_SOURCEDIR_H -#define EPT_DEBTAGS_SOURCEDIR_H - -/** @file - * @author Enrico Zini <enrico@enricozini.org> - * Debtags data source directory access - */ - -/* - * Copyright (C) 2003--2013 Enrico Zini <enrico@debian.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <string> -#include <wibble/sys/fs.h> - -namespace ept { -namespace debtags { - -class Vocabulary; - -/** - * Access a directory containing Debtags data files - */ -class SourceDir : public wibble::sys::fs::Directory -{ -protected: - enum FileType { SKIP, TAG, VOC, TAGGZ, VOCGZ }; - - // Check if a file name is a tag file, a vocabulary file or a file to skip. - // Please notice that it works on file names, not paths. - FileType fileType(const std::string& name); - -public: - SourceDir(const std::string& path); - ~SourceDir(); - - /// Return the time of the newest file in the source directory - time_t timestamp(); - - /// Return the time of the newest vocabulary file in the source directory - time_t vocTimestamp(); - - /// Return the time of the newest tag file in the source directory - time_t tagTimestamp(); - - /// Read the tag files in the directory and output their content to out - template<typename OUT> - void readTags(OUT out); - - /** - * Read the vocabulary files in the directory and output their content to - * out - */ - void readVocabularies(Vocabulary& out); -}; - -} -} - -// vim:set ts=4 sw=4: -#endif diff --git a/ept/debtags/maint/sourcedir.tcc b/ept/debtags/maint/sourcedir.tcc deleted file mode 100644 index ab31e9b..0000000 --- a/ept/debtags/maint/sourcedir.tcc +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef EPT_DEBTAGS_SOURCEDIR_TCC -#define EPT_DEBTAGS_SOURCEDIR_TCC - -/** @file - * @author Enrico Zini <enrico@enricozini.org> - * Debtags data source directory access - */ -#include <ept/debtags/maint/sourcedir.h> - -#include <tagcoll/input/zlib.h> -#include <tagcoll/input/stdio.h> -#include <wibble/sys/fs.h> - -using namespace wibble; - -namespace ept { -namespace debtags { - -template<typename OUT> -void SourceDir::readTags(OUT out) -{ - if (!exists()) return; - - for (const_iterator d = begin(); d != end(); ++d) - { - string name = *d; - FileType type = fileType(name); - if (type == TAG) - { - // Read uncompressed data - tagcoll::input::Stdio in(m_path + "/" + name); - - // Read the collection - tagcoll::textformat::parse(in, out); - } - else if (type == TAGGZ) - { - // Read compressed data - tagcoll::input::Zlib in(m_path + "/" + name); - - // Read the collection - tagcoll::textformat::parse(in, out); - } - } -} - -} -} - -#include <tagcoll/TextFormat.tcc> - -#endif - -// -*- C++ -*- -// vim:set ts=4 sw=4: |