From 521e760de26718bf5d59b9bcfddd1a642f378038 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Mon, 30 Jul 2012 16:43:05 +0200 Subject: [PATCH] Changed: #1440 Moved some filepath functions --HG-- branch : build_pipeline_v3 --- .../pipeline/service/database_status.cpp | 107 +------------ .../tools/pipeline/service/database_status.h | 10 +- .../pipeline/service/metadata_storage.cpp | 55 +++++++ .../tools/pipeline/service/metadata_storage.h | 73 +++++++++ .../pipeline/service/workspace_storage.cpp | 144 ++++++++++++++++++ .../pipeline/service/workspace_storage.h | 59 +++++++ 6 files changed, 337 insertions(+), 111 deletions(-) create mode 100644 code/nel/tools/pipeline/service/metadata_storage.cpp create mode 100644 code/nel/tools/pipeline/service/metadata_storage.h create mode 100644 code/nel/tools/pipeline/service/workspace_storage.cpp create mode 100644 code/nel/tools/pipeline/service/workspace_storage.h diff --git a/code/nel/tools/pipeline/service/database_status.cpp b/code/nel/tools/pipeline/service/database_status.cpp index 8d255cf0d..5c3bbbe24 100644 --- a/code/nel/tools/pipeline/service/database_status.cpp +++ b/code/nel/tools/pipeline/service/database_status.cpp @@ -48,107 +48,10 @@ namespace PIPELINE { namespace { -/// Input must be normalized path -bool isInRootDirectoryFast(std::string &rootDirectoryName, std::string &rootDirectoryPath, const std::string &path) -{ - //return path.find(g_DatabaseDirectory) == 0; - CConfigFile::CVar &rootDirectories = NLNET::IService::getInstance()->ConfigFile.getVar("RootDirectories"); - for (uint i = 0; i < rootDirectories.size(); ++i) - { - rootDirectoryName = rootDirectories.asString(i); - CConfigFile::CVar &dir = NLNET::IService::getInstance()->ConfigFile.getVar(rootDirectoryName); - rootDirectoryPath = standardizePath(dir.asString(), true); - if (path.find(rootDirectoryPath) == 0) return true; - } - return false; -} - -bool isInSheetsDirectoryFast(std::string &sheetDirectoryName, std::string &sheetDirectoryPath, const std::string &path) -{ - { - sheetDirectoryName = "WorkspaceDfnDirectory"; - CConfigFile::CVar &dir = NLNET::IService::getInstance()->ConfigFile.getVar(sheetDirectoryName); - sheetDirectoryPath = standardizePath(dir.asString(), true); - if (path.find(sheetDirectoryPath) == 0) return true; - } - { - sheetDirectoryName = "WorkspaceSheetDirectory"; - CConfigFile::CVar &dir = NLNET::IService::getInstance()->ConfigFile.getVar(sheetDirectoryName); - sheetDirectoryPath = standardizePath(dir.asString(), true); - if (path.find(sheetDirectoryPath) == 0) return true; - } - return false; -} - -/// Input must be normalized path -bool isInWorkspaceDirectoryFast(const std::string &path) -{ - return path.find(g_WorkDir) == 0; -} - -/// Input must be normalized path in database directory -std::string dropRootDirectoryFast(const std::string &path, const std::string &rootDirectoryPath) -{ - return path.substr(rootDirectoryPath.length()); -} - -/// Input must be normalized path in sheets directory -std::string dropSheetDirectoryFast(const std::string &path, const std::string &sheetDirectoryPath) -{ - return path.substr(sheetDirectoryPath.length()); -} - -/// Input must be normalized path in pipeline directory -std::string dropWorkspaceDirectoryFast(const std::string &path) -{ - return path.substr(g_WorkDir.length()); -} - -} /* anonymous namespace */ - -std::string getMetaFilePath(const std::string &path, const std::string &dotSuffix) -{ - std::string stdPath = standardizePath(path, false); - if (isInWorkspaceDirectoryFast(stdPath)) - { - // TODO_TEST - std::string relPath = dropWorkspaceDirectoryFast(stdPath); - std::string::size_type slashPos = relPath.find_first_of('/'); - std::string proProName = relPath.substr(0, slashPos); - std::string subPath = relPath.substr(slashPos); - return g_WorkDir + proProName + PIPELINE_DATABASE_META_SUFFIX + subPath + dotSuffix; - } - else - { - std::string rootDirectoryName; - std::string rootDirectoryPath; - if (isInSheetsDirectoryFast(rootDirectoryName, rootDirectoryPath, stdPath)) - { - std::string relPath = dropSheetDirectoryFast(stdPath, rootDirectoryPath); - return g_WorkDir + PIPELINE_DIRECTORY_PREFIX_SHEET + NLMISC::toLower(rootDirectoryName) + PIPELINE_DATABASE_META_SUFFIX + "/" + relPath + dotSuffix; - } - else - { - if (isInRootDirectoryFast(rootDirectoryName, rootDirectoryPath, stdPath)) - { - std::string relPath = dropRootDirectoryFast(stdPath, rootDirectoryPath); - return g_WorkDir + PIPELINE_DIRECTORY_PREFIX_ROOT + NLMISC::toLower(rootDirectoryName) + PIPELINE_DATABASE_META_SUFFIX + "/" + relPath + dotSuffix; - } - else - { - nlerror("Path is not in database or pipeline (%s)", path.c_str()); - return path + dotSuffix; - } - } - } -} - -namespace { - /// Create status file path std::string getStatusFilePath(const std::string &path) { - return getMetaFilePath(path, PIPELINE_DATABASE_STATUS_SUFFIX); + return CWorkspaceStorage::getMetaFilePath(path, PIPELINE_DATABASE_STATUS_SUFFIX); } } /* anonymous namespace */ @@ -279,7 +182,7 @@ bool CDatabaseStatus::getFileStatus(std::map &fileStat return false; } - std::string dirPathMeta = getMetaFilePath(dirPath, ""); + std::string dirPathMeta = CWorkspaceStorage::getMetaFilePath(dirPath, ""); std::vector dirContentsMeta; CPath::getPathContent(dirPathMeta, false, false, true, dirContentsMeta); @@ -328,7 +231,7 @@ bool CDatabaseStatus::getFileStatus(std::map &fileStat // TODO_PROCESS_WARNING nlwarning("Requesting status on file or directory '%s' that does not exist!", path.c_str()); CFileRemove fr; - std::string removedTagFile = getMetaFilePath(path, PIPELINE_DATABASE_REMOVE_SUFFIX); + std::string removedTagFile = CWorkspaceStorage::getMetaFilePath(path, PIPELINE_DATABASE_REMOVE_SUFFIX); if (CFile::isExists(removedTagFile)) { // file existed before @@ -424,7 +327,7 @@ public: fs.LastFileSizeReference = fisz; } - std::string removePath = getMetaFilePath(FilePath, PIPELINE_DATABASE_REMOVE_SUFFIX); + std::string removePath = CWorkspaceStorage::getMetaFilePath(FilePath, PIPELINE_DATABASE_REMOVE_SUFFIX); StatusMutex->lock(); { @@ -615,7 +518,7 @@ void updateDirectoryStatus(CDatabaseStatus* ds, CDatabaseStatusUpdater &updater, // Note that we won't notice when a directory is deleted, this is also not necessary because we never work recursively in the service. // Any recursive lookups are done in specific unsafe build tools that are tagged as unsafe and not monitored by the pipeline. - std::string dirPathMeta = getMetaFilePath(dirPath, ""); + std::string dirPathMeta = CWorkspaceStorage::getMetaFilePath(dirPath, ""); // nldebug("META DIR: %s", dirPathMeta.c_str()); std::vector dirContentsMeta; diff --git a/code/nel/tools/pipeline/service/database_status.h b/code/nel/tools/pipeline/service/database_status.h index e688dc22b..22f11cef9 100644 --- a/code/nel/tools/pipeline/service/database_status.h +++ b/code/nel/tools/pipeline/service/database_status.h @@ -41,6 +41,7 @@ // Project includes #include "callback.h" +#include "metadata_storage.h" namespace NLMISC { class IRunnable; @@ -52,15 +53,6 @@ namespace PIPELINE { //#define PIPELINE_DATABASE_ERRORS_SUBDIR "database.errors/" //#define PIPELINE_DATABASE_DEPEND_SUBDIR "database.depend/" -#define PIPELINE_DATABASE_STATUS_SUFFIX ".status" -#define PIPELINE_DATABASE_ERRORS_SUFFIX ".errors" -#define PIPELINE_DATABASE_DEPEND_SUFFIX ".depend" -#define PIPELINE_DATABASE_REMOVE_SUFFIX ".remove" - -#define PIPELINE_DATABASE_META_SUFFIX ".meta" - -std::string getMetaFilePath(const std::string &path, const std::string &dotSuffix); - // Status is generated CRC32 for reference. // Errors are errors caused by using this file as an input or output file. diff --git a/code/nel/tools/pipeline/service/metadata_storage.cpp b/code/nel/tools/pipeline/service/metadata_storage.cpp new file mode 100644 index 000000000..6a0998fae --- /dev/null +++ b/code/nel/tools/pipeline/service/metadata_storage.cpp @@ -0,0 +1,55 @@ +/** + * \file metadata_storage.cpp + * \brief CMetadataStorage + * \date 2012-07-30 14:31GMT + * \author Jan Boon (Kaetemi) + * CMetadataStorage + */ + +/* + * Copyright (C) 2012 by authors + * + * This file is part of RYZOM CORE PIPELINE. + * RYZOM CORE PIPELINE is free software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * RYZOM CORE PIPELINE 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with RYZOM CORE PIPELINE. If not, see + * . + */ + +#include +#include "metadata_storage.h" + +// STL includes + +// NeL includes +// #include + +// Project includes + +using namespace std; +// using namespace NLMISC; + +namespace PIPELINE { + +CMetadataStorage::CMetadataStorage() +{ + +} + +CMetadataStorage::~CMetadataStorage() +{ + +} + +} /* namespace PIPELINE */ + +/* end of file */ diff --git a/code/nel/tools/pipeline/service/metadata_storage.h b/code/nel/tools/pipeline/service/metadata_storage.h new file mode 100644 index 000000000..0ea460d8d --- /dev/null +++ b/code/nel/tools/pipeline/service/metadata_storage.h @@ -0,0 +1,73 @@ +/** + * \file metadata_storage.h + * \brief CMetadataStorage + * \date 2012-07-30 14:31GMT + * \author Jan Boon (Kaetemi) + * CMetadataStorage + */ + +/* + * Copyright (C) 2012 by authors + * + * This file is part of RYZOM CORE PIPELINE. + * RYZOM CORE PIPELINE is free software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * RYZOM CORE PIPELINE 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with RYZOM CORE PIPELINE. If not, see + * . + */ + +#ifndef PIPELINE_METADATA_STORAGE_H +#define PIPELINE_METADATA_STORAGE_H +#include + +// STL includes + +// NeL includes + +// Project includes +#include "workspace_storage.h" + +namespace PIPELINE { + +/// Suffix for metafiles that contain the CRC32 etc +#define PIPELINE_DATABASE_STATUS_SUFFIX ".status" +/// Suffix for metafiles that contain error info on database files +#define PIPELINE_DATABASE_ERRORS_SUFFIX ".errors" +/// Suffix for metafiles that contain dependencies for a file +#define PIPELINE_DATABASE_DEPEND_SUFFIX ".depend" +/// Suffix for metafiles that refer to a previously known file that no longer exists +#define PIPELINE_DATABASE_REMOVE_SUFFIX ".remove" + +/** + * \brief CMetadataStorage + * \date 2012-07-30 14:31GMT + * \author Jan Boon (Kaetemi) + * CMetadataStorage + */ +class CMetadataStorage +{ +protected: + // pointers + // ... + + // instances + // ... +public: + CMetadataStorage(); + virtual ~CMetadataStorage(); +}; /* class CMetadataStorage */ + +} /* namespace PIPELINE */ + +#endif /* #ifndef PIPELINE_METADATA_STORAGE_H */ + +/* end of file */ diff --git a/code/nel/tools/pipeline/service/workspace_storage.cpp b/code/nel/tools/pipeline/service/workspace_storage.cpp new file mode 100644 index 000000000..d8ca370da --- /dev/null +++ b/code/nel/tools/pipeline/service/workspace_storage.cpp @@ -0,0 +1,144 @@ +/** + * \file workspace_storage.cpp + * \brief CWorkspaceStorage + * \date 2012-07-30 14:34GMT + * \author Jan Boon (Kaetemi) + * CWorkspaceStorage + */ + +/* + * Copyright (C) 2012 by authors + * + * This file is part of RYZOM CORE PIPELINE. + * RYZOM CORE PIPELINE is free software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * RYZOM CORE PIPELINE 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with RYZOM CORE PIPELINE. If not, see + * . + */ + +#include +#include "workspace_storage.h" + +// STL includes + +// NeL includes +// #include +#include + +// Project includes +#include "pipeline_service.h" + +// using namespace std; +// using namespace NLMISC; + +namespace PIPELINE { + +namespace { + +/// Input must be normalized path +bool isInRootDirectoryFast(std::string &rootDirectoryName, std::string &rootDirectoryPath, const std::string &path) +{ + //return path.find(g_DatabaseDirectory) == 0; + NLMISC::CConfigFile::CVar &rootDirectories = NLNET::IService::getInstance()->ConfigFile.getVar("RootDirectories"); + for (uint i = 0; i < rootDirectories.size(); ++i) + { + rootDirectoryName = rootDirectories.asString(i); + NLMISC::CConfigFile::CVar &dir = NLNET::IService::getInstance()->ConfigFile.getVar(rootDirectoryName); + rootDirectoryPath = standardizePath(dir.asString(), true); + if (path.find(rootDirectoryPath) == 0) return true; + } + return false; +} + +bool isInSheetsDirectoryFast(std::string &sheetDirectoryName, std::string &sheetDirectoryPath, const std::string &path) +{ + { + sheetDirectoryName = "WorkspaceDfnDirectory"; + NLMISC::CConfigFile::CVar &dir = NLNET::IService::getInstance()->ConfigFile.getVar(sheetDirectoryName); + sheetDirectoryPath = standardizePath(dir.asString(), true); + if (path.find(sheetDirectoryPath) == 0) return true; + } + { + sheetDirectoryName = "WorkspaceSheetDirectory"; + NLMISC::CConfigFile::CVar &dir = NLNET::IService::getInstance()->ConfigFile.getVar(sheetDirectoryName); + sheetDirectoryPath = standardizePath(dir.asString(), true); + if (path.find(sheetDirectoryPath) == 0) return true; + } + return false; +} + +/// Input must be normalized path +bool isInWorkspaceDirectoryFast(const std::string &path) +{ + return path.find(g_WorkDir) == 0; +} + +/// Input must be normalized path in database directory +std::string dropRootDirectoryFast(const std::string &path, const std::string &rootDirectoryPath) +{ + return path.substr(rootDirectoryPath.length()); +} + +/// Input must be normalized path in sheets directory +std::string dropSheetDirectoryFast(const std::string &path, const std::string &sheetDirectoryPath) +{ + return path.substr(sheetDirectoryPath.length()); +} + +/// Input must be normalized path in pipeline directory +std::string dropWorkspaceDirectoryFast(const std::string &path) +{ + return path.substr(g_WorkDir.length()); +} + +} /* anonymous namespace */ + +std::string CWorkspaceStorage::getMetaFilePath(const std::string &path, const std::string &dotSuffix) +{ + std::string stdPath = standardizePath(path, false); + if (isInWorkspaceDirectoryFast(stdPath)) + { + // TODO_TEST + std::string relPath = dropWorkspaceDirectoryFast(stdPath); + std::string::size_type slashPos = relPath.find_first_of('/'); + std::string proProName = relPath.substr(0, slashPos); + std::string subPath = relPath.substr(slashPos); + return g_WorkDir + proProName + PIPELINE_DATABASE_META_SUFFIX + subPath + dotSuffix; + } + else + { + std::string rootDirectoryName; + std::string rootDirectoryPath; + if (isInSheetsDirectoryFast(rootDirectoryName, rootDirectoryPath, stdPath)) + { + std::string relPath = dropSheetDirectoryFast(stdPath, rootDirectoryPath); + return g_WorkDir + PIPELINE_DIRECTORY_PREFIX_SHEET + NLMISC::toLower(rootDirectoryName) + PIPELINE_DATABASE_META_SUFFIX + "/" + relPath + dotSuffix; + } + else + { + if (isInRootDirectoryFast(rootDirectoryName, rootDirectoryPath, stdPath)) + { + std::string relPath = dropRootDirectoryFast(stdPath, rootDirectoryPath); + return g_WorkDir + PIPELINE_DIRECTORY_PREFIX_ROOT + NLMISC::toLower(rootDirectoryName) + PIPELINE_DATABASE_META_SUFFIX + "/" + relPath + dotSuffix; + } + else + { + nlerror("Path is not in database or pipeline (%s)", path.c_str()); + return path + dotSuffix; + } + } + } +} + +} /* namespace PIPELINE */ + +/* end of file */ diff --git a/code/nel/tools/pipeline/service/workspace_storage.h b/code/nel/tools/pipeline/service/workspace_storage.h new file mode 100644 index 000000000..2cc889687 --- /dev/null +++ b/code/nel/tools/pipeline/service/workspace_storage.h @@ -0,0 +1,59 @@ +/** + * \file workspace_storage.h + * \brief CWorkspaceStorage + * \date 2012-07-30 14:34GMT + * \author Jan Boon (Kaetemi) + * CWorkspaceStorage + */ + +/* + * Copyright (C) 2012 by authors + * + * This file is part of RYZOM CORE PIPELINE. + * RYZOM CORE PIPELINE is free software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * RYZOM CORE PIPELINE 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with RYZOM CORE PIPELINE. If not, see + * . + */ + +#ifndef PIPELINE_WORKSPACE_STORAGE_H +#define PIPELINE_WORKSPACE_STORAGE_H +#include + +// STL includes + +// NeL includes + +// Project includes + +namespace PIPELINE { + +/// Suffix for directories under the workspace containing the metafiles +#define PIPELINE_DATABASE_META_SUFFIX ".meta" + +/** + * \brief CWorkspaceStorage + * \date 2012-07-30 14:34GMT + * \author Jan Boon (Kaetemi) + * CWorkspaceStorage + */ +class CWorkspaceStorage +{ +public: + static std::string getMetaFilePath(const std::string &path, const std::string &dotSuffix); +}; /* class CWorkspaceStorage */ + +} /* namespace PIPELINE */ + +#endif /* #ifndef PIPELINE_WORKSPACE_STORAGE_H */ + +/* end of file */