diff --git a/.gitignore b/.gitignore index aae4bf6..33c727a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,22 +2,32 @@ *.slo *.lo *.o +*.obj # Compiled Dynamic libraries *.so *.dylib +*.dll # Compiled Static libraries *.lai *.la *.a +*.lib + +# Compiled executables +*.exe # Build directories build/ bin/ +debug/ +release/ +.vs/ # Backup files *~ +*.bak # Auto tools generated files. .deps/ @@ -40,3 +50,6 @@ compile libtocc/src/libtocc.pc libtocc/tests/libtocctests +# Catch2 files +catch_amalgamated.cpp +catch_amalgamated.hpp diff --git a/cli/docs/source/compile.rst b/cli/docs/source/compile.rst index d7ea16e..95dbf23 100644 --- a/cli/docs/source/compile.rst +++ b/cli/docs/source/compile.rst @@ -4,8 +4,8 @@ :hidden: -How to Compile Tocc's Official CLI -================================== +How to Compile Tocc's Official CLI in a Unix-like OS (Linux, BSD, etc) +====================================================================== In order to compile CLI, you need first have ``libtocc`` compiled and installed. Follow the instructions in @@ -62,3 +62,14 @@ This will install ``tocc`` binary in the directory you specified using ``--prefix`` (or the default directory). + +How to Compile Tocc's Official CLI in Windows using Microsoft Visual C++ +======================================================================== + +1. Open solution file ``tocc\msvc\libtocctests.sln`` in MSVC. +2. Select project ``tocc``. +3. Build this project. +4. Select project ``tocc-initialize``. +5. Build this project. +6. The programs will be ``tocc.exe`` and ``tocc-initialize`` in directory ``tocc\msvc\x64\release`` or ``tocc\msvc\x64\debug``. + diff --git a/cli/src/TOCCFILES.DB b/cli/src/TOCCFILES.DB new file mode 100644 index 0000000..c46e604 Binary files /dev/null and b/cli/src/TOCCFILES.DB differ diff --git a/cli/src/actions/assign_action.cpp b/cli/src/actions/assign_action.cpp index 6452cee..c5993b7 100644 --- a/cli/src/actions/assign_action.cpp +++ b/cli/src/actions/assign_action.cpp @@ -56,7 +56,8 @@ namespace tocccli } // Converting files vector to array. - const char* files_array[files.size()]; + const char* sizevar; + const char** files_array = (const char**) malloc(files.size() * sizeof sizevar); for (int i = 0; i < files.size(); i++) { files_array[i] = files[i].get_id(); @@ -71,5 +72,6 @@ namespace tocccli } this->libtocc_manager->assign_tags(files_array, files.size(), &tags_collection); + free(files_array); } } diff --git a/cli/src/actions/remove_action.cpp b/cli/src/actions/remove_action.cpp index e71507e..ce6f936 100644 --- a/cli/src/actions/remove_action.cpp +++ b/cli/src/actions/remove_action.cpp @@ -55,7 +55,8 @@ namespace tocccli } //Extracting files ids into an array - const char* file_ids[files.size()]; + const char* sizevar; + const char** file_ids = (const char**)malloc(files.size() * sizeof sizevar); for(int i = 0; i < files.size(); i++) { file_ids[i] = files[i].get_id(); @@ -66,5 +67,6 @@ namespace tocccli { this->libtocc_manager->remove_files(file_ids, files.size()); } + free(file_ids); } } diff --git a/cli/src/actions/set_title_action.cpp b/cli/src/actions/set_title_action.cpp index f9f3289..2e63fe1 100644 --- a/cli/src/actions/set_title_action.cpp +++ b/cli/src/actions/set_title_action.cpp @@ -60,12 +60,14 @@ namespace tocccli } //extract file ids to an array - const char* file_ids[files.size()]; + const char* sizevar; + const char** file_ids = (const char**)malloc(files.size() * sizeof sizevar); for(int i = 0; i < files.size(); i++) { file_ids[i] = files[i].get_id(); } this->libtocc_manager->set_titles(file_ids, files.size(), cmd_arguments.front().c_str()); + free(file_ids); } } diff --git a/cli/src/actions/tags_statistics_action.cpp b/cli/src/actions/tags_statistics_action.cpp index b26511e..4a79ccf 100644 --- a/cli/src/actions/tags_statistics_action.cpp +++ b/cli/src/actions/tags_statistics_action.cpp @@ -70,7 +70,8 @@ namespace tocccli else { // Converting files vector to array of IDs. - const char* files_array[files.size()]; + const char* sizevar; + const char** files_array = (const char**)malloc(files.size() * sizeof sizevar); for (int i = 0; i < files.size(); i++) { files_array[i] = files[i].get_id(); @@ -78,6 +79,7 @@ namespace tocccli statistics_collection = this->libtocc_manager->get_tags_statistics(files_array, files.size()); + free(files_array); } // Print statistics in a pretty format. diff --git a/cli/src/actions/unassign_action.cpp b/cli/src/actions/unassign_action.cpp index 98a5b6a..e30ad2f 100644 --- a/cli/src/actions/unassign_action.cpp +++ b/cli/src/actions/unassign_action.cpp @@ -54,9 +54,9 @@ namespace tocccli { throw InvalidParametersError("-u, --unassign, must have at least one argument."); } - - // Converting files vector to array. - const char* files_array[files.size()]; + // Converting files vector to array. + const char* sizevar; + const char** files_array = (const char**)malloc(files.size() * sizeof sizevar); for (int i = 0; i < files.size(); i++) { files_array[i] = files[i].get_id(); @@ -71,5 +71,6 @@ namespace tocccli } this->libtocc_manager->unassign_tags(files_array, files.size(), &tags_collection); + free(files_array); } } diff --git a/cli/src/initializer.cpp b/cli/src/initializer.cpp index 93cb893..ef4483d 100644 --- a/cli/src/initializer.cpp +++ b/cli/src/initializer.cpp @@ -22,7 +22,11 @@ */ #include +#ifdef _MSC_VER +#include "unistdx.h" +#else #include // getcwd +#endif #include // FILENAME_MAX #include @@ -55,6 +59,9 @@ int main(int argc, char* argv[]) { // Using current directory as the base path. char path_buffer[FILENAME_MAX]; +#ifdef _MSC_VER +#define getcwd _getcwd +#endif if (!getcwd(path_buffer, FILENAME_MAX)) { std::cout << tocccli::translate_errno(errno) << std::endl; diff --git a/cli/src/main.cpp b/cli/src/main.cpp index deeea32..ee9cbda 100644 --- a/cli/src/main.cpp +++ b/cli/src/main.cpp @@ -19,7 +19,11 @@ #include #include #include +#ifdef _MSC_VER +#include "unistdx.h" +#else #include // getcwd +#endif #include // FILENAME_MAX #include #include @@ -50,6 +54,9 @@ int main(int argc, char* argv[]) // Finding the current directory (default of Base Path). char path_buffer[FILENAME_MAX]; +#ifdef _MSC_VER +#define getcwd _getcwd +#endif if (!getcwd(path_buffer, FILENAME_MAX)) { std::cout << translate_errno(errno) << std::endl; diff --git a/libtocc/docs/source/compile.rst b/libtocc/docs/source/compile.rst index a36599a..e0ae589 100644 --- a/libtocc/docs/source/compile.rst +++ b/libtocc/docs/source/compile.rst @@ -15,14 +15,13 @@ Un-compress the package, then run:: $ make $ make install +Compiling libtocc for Unix-like OS's (Linux, BSD, etc) +------------------------------------------------------ -Compiling libtocc ------------------ - -1. Bootstraiping +1. Bootstrapping ^^^^^^^^^^^^^^^^ -First step is bootstraping configure scripts. (You only need to do this if +First step is bootstrapping configure scripts. (You only need to do this if you get the latest source from the repository. If you have one of the released source packages, this step is already done for you.) @@ -52,7 +51,7 @@ want to install it somewhere else, you can pass ``--prefix`` option to the $ ./configure --prefix=/opt/libtocc/ -In the above example, builded libraries will be placed in ``/opt/libtocc/lib/`` +In the above example, built libraries will be placed in ``/opt/libtocc/lib/`` and public headers in ``/opt/libtocc/include``. **Optimized/Debug Build**: By default, *libtocc* mades with ``-g`` and ``-O2``. @@ -86,29 +85,57 @@ prefix. For example, if prefix is ``/usr/local/``, libraries will be copied to ``/usr/local/lib/`` and headers to ``/usr/local/include``. +Compiling libtocc for Windows with Microsoft Visual C++ +------------------------------------------------------- + +Note: libtocc does not compile correctly with MSVC 2019 but it does with +MSVC 2017 or MSVC 2021. + +1. Open solution file ``tocc\msvc\libtocctests.sln`` in MSVC. + +2. Select project ``libtocc`` and do a build. + +3. The library file will be produced in ``tocc\msvc\x64\release\libtocc.lib`` or ``tocc\msvc\x64\debug\libtocc.lib`` + + + + + Test Units ---------- *libtocc* comes with some Unit Tests. They're placed in ``libtocc/tests`` directory. This section explains how to build and run these Unit Tests. -Installing Catch.hpp -^^^^^^^^^^^^^^^^^^^^ -Tests are using `Catch `_ library. The Tocc's -source code hadn't updated and it depends on the version 1 of Catch. +Installing Catch2 for Unix-like OS's (Linux, BSD, etc) +------------------------------------------------------ -Download ``catch.hpp`` from `Catch 1.10.0 `_ -and copy it to ``/usr/local/include``. Or alternatevly, copy it to another directory -and add a ``-I`` flag to the ``./configure`` command below to point to that directory. +1. Download Catch2 to a temporary directory. Make sure you have the ``devel`` branch. +2. cd to the ``extras`` suddirectory of the temporary directory. +3. Invoke: -1. Bootstraping -^^^^^^^^^^^^^^^ -Just like the bootstraping step of *libtocc* itself, you need Gnu Auto Tools. + $ gcc cache_amalgamated.cpp -o cache_amalgamated.o + + $ ar rcs libcache_amalgamated.a cache_amalgamatd.o + + $ sudo cp libcache_amalgamated.a /usr/local/lib + + $ sudo cp cache_amalgamated.hpp /usr/local/include + + +Building and running test units for Unix-like OS's (Linux, BSD, etc.) +--------------------------------------------------------------------- + +1. Bootstrapping +^^^^^^^^^^^^^^^^ +Just like the bootstrapping step of *libtocc* itself, you need Gnu Auto Tools. Then invoke:: + ' $ cd /path/to/libtocc/tests $ ./bootstrap - + +' 2. Configuring ^^^^^^^^^^^^^^ @@ -116,7 +143,11 @@ Previous step creates a ``configure`` script. To run it, you need to add ``libtocc/src/`` directory to the includes path. The following command should do it:: - $ ./configure CPPFLAGS="-I../src/" CXXFLAGS="-I../src/" + $ ./configure CPPFLAGS="-I../src/ -I../tests" LDFLAGS="-L/usr/local/lib" CXXFLAGS="-I../src/ -I../tests" LIBS="-lcatch_amalgamated" + +You can do this by typing: + + $ ./config Also, if you installed *libtocc* library in a non-standard path (where ``ld`` can't find it by default, say ``/opt/libtocc/lib/``) you need to add that to @@ -160,8 +191,27 @@ Then send ``tests.log`` file to *tocc@aidinhut.com*, and provide your platform information, such as your OS and its version. -Linking Your Software with *libtocc* ------------------------------------- +Installing Catch2 for Windows +------------------------------------------------------ + +1. Download Catch2 to a temporary directory. Make sure you have the ``devel`` branch. +2. cd to the ``extras`` suddirectory of the temporary directory. +3. Copy ``libcache_amalgamated.cpp`` and ``cache_amalgamated.hpp`` to ``tocc/libtocc/tests`` + + + +Building and running test units for Windows with Microsoft Visual C++ +--------------------------------------------------------------------- + +1. Open solution file ``tocc\msvc\libtocctests.sln`` in MSVC. +2. Select project ``libtocctests``. +3. Build this project. +4. The program will be in ``tocc\msvc\x64\release\libtocctests.exe`` or ``tocc\msvc\x64\debug\libtocctests.exe``. Execute the program from a command prompt. + + + +Linking Your Software with *libtocc* for Unix-like OS's (Linux, BSD, etc) +------------------------------------------------------------------------- Using Autotools ^^^^^^^^^^^^^^^ diff --git a/libtocc/src/libtocc/common/database_exceptions.cpp b/libtocc/src/libtocc/common/database_exceptions.cpp index e6493f8..769c823 100644 --- a/libtocc/src/libtocc/common/database_exceptions.cpp +++ b/libtocc/src/libtocc/common/database_exceptions.cpp @@ -16,6 +16,10 @@ * along with Tocc. If not, see . */ +#ifdef _MSC_VER +#pragma warning(disable: 4996) +#endif + #include "libtocc/common/database_exceptions.h" #include diff --git a/libtocc/src/libtocc/common/file_system_exceptions.cpp b/libtocc/src/libtocc/common/file_system_exceptions.cpp index 766163e..19f6a61 100644 --- a/libtocc/src/libtocc/common/file_system_exceptions.cpp +++ b/libtocc/src/libtocc/common/file_system_exceptions.cpp @@ -17,6 +17,9 @@ */ #include "libtocc/common/file_system_exceptions.h" +//#ifdef _MSC_VER +#pragma warning(disable: 4996) +//#endif #include #include // For `strerror'. diff --git a/libtocc/src/libtocc/database/base_exception.cpp b/libtocc/src/libtocc/database/base_exception.cpp new file mode 100644 index 0000000..3bc50f4 --- /dev/null +++ b/libtocc/src/libtocc/database/base_exception.cpp @@ -0,0 +1,28 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#include "libtocc/common/base_exception.h" + + +namespace libtocc +{ + + BaseException::~BaseException() throw() + { + } +} diff --git a/libtocc/src/libtocc/database/base_exception.h b/libtocc/src/libtocc/database/base_exception.h new file mode 100644 index 0000000..926ccf6 --- /dev/null +++ b/libtocc/src/libtocc/database/base_exception.h @@ -0,0 +1,38 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + + +#ifndef LIBTOCC_BASE_EXCEPTION_H_INCLUDED +#define LIBTOCC_BASE_EXCEPTION_H_INCLUDED + +#include + + +namespace libtocc +{ + /* + * Base class for all exceptions in libtocc. + */ + class BaseException : public std::exception + { + public: + virtual ~BaseException() throw(); + }; +} + +#endif /* LIBTOCC_BASE_EXCEPTION_H_INCLUDED */ diff --git a/libtocc/src/libtocc/database/database.cpp b/libtocc/src/libtocc/database/database.cpp index 24de8b9..a631fed 100644 --- a/libtocc/src/libtocc/database/database.cpp +++ b/libtocc/src/libtocc/database/database.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "libtocc/database/base23.h" #include "libtocc/database/scripts.h" @@ -36,7 +37,6 @@ extern "C" namespace libtocc { - /* * Holds a pointer of Unqlite VM. * The purpose is to ensure that pointer is released properly. @@ -771,11 +771,11 @@ namespace libtocc throw DatabaseScriptCompilationError(error_message.str().c_str()); } } - +#include Database::Database(std::string database_file) { this->database_file = database_file; - } + } Database::~Database() { @@ -789,7 +789,7 @@ namespace libtocc if (!db_file_stream.good()) { db_file_stream.close(); - std::string message("No database found in the base path specified."); + std::string message(std::string("No database found in the base path specified: [") + this->database_file + std::string ("]")); message += " Make sure the path is correct, and it's initialized."; throw DatabaseInitializationError(message.c_str()); } @@ -831,7 +831,7 @@ namespace libtocc } // Checking if the database file already exists. std::ifstream db_file_stream(this->database_file.c_str()); - if (db_file_stream) + if (db_file_stream) { db_file_stream.close(); @@ -844,7 +844,6 @@ namespace libtocc unqlite* db_pointer; result = unqlite_open(&db_pointer, this->database_file.c_str(), UNQLITE_OPEN_CREATE); UnqliteDBHolder db_holder(db_pointer); - if (result != UNQLITE_OK) { std::stringstream message_stream; @@ -878,6 +877,7 @@ namespace libtocc IntFileInfo Database::create_file(std::vector tags, std::string title, std::string traditional_path) + { // Opening database in write mode. unqlite* db_pointer = open_db(false); diff --git a/libtocc/src/libtocc/database/database.h b/libtocc/src/libtocc/database/database.h index 61577c9..c61ee0f 100644 --- a/libtocc/src/libtocc/database/database.h +++ b/libtocc/src/libtocc/database/database.h @@ -18,9 +18,10 @@ #ifndef LIBTOCC_DATABASE_H_INCLUDED #define LIBTOCC_DATABASE_H_INCLUDED - +//#define DATABASE_FILE "TOCCFILE" #include #include +static const std::string DATABASE_FILE = "TOCCFILE"; #include "libtocc/exprs/query.h" #include "libtocc/common/int_file_info.h" @@ -29,6 +30,8 @@ // Forward declaration of unqlite. So I don't have to include the // unqlite.h in my header, so it will be hidden from the others // who include this header. + + struct unqlite; namespace libtocc @@ -171,6 +174,7 @@ namespace libtocc * @param new_title : the new file's title */ void set_titles(const std::vector& file_ids, const std::string& new_title); + private: std::string database_file; diff --git a/libtocc/src/libtocc/database/database_exceptions.cpp b/libtocc/src/libtocc/database/database_exceptions.cpp new file mode 100644 index 0000000..769c823 --- /dev/null +++ b/libtocc/src/libtocc/database/database_exceptions.cpp @@ -0,0 +1,116 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#ifdef _MSC_VER +#pragma warning(disable: 4996) +#endif + +#include "libtocc/common/database_exceptions.h" +#include + +namespace libtocc +{ + + BaseDatabaseException::BaseDatabaseException(const char* message) throw() + { + /* String copy message to this->message to avoid using + * pointer which is invalidated during stack unwind when + * the exception is thrown. + */ + this->message = new char[strlen(message) + 1]; + strcpy(this->message, message); + } + + BaseDatabaseException::BaseDatabaseException(const BaseDatabaseException& source) throw() + { + this->message = new char[strlen(source.message) + 1]; + strcpy(this->message, source.message); + } + + BaseDatabaseException& BaseDatabaseException::operator=(const BaseDatabaseException& source) throw() + { + if (this == &source) + { + return *this; + } + + if (this->message != NULL) + { + delete[] this->message; + } + + this->message = new char[strlen(source.message) + 1]; + strcpy(this->message, source.message); + + return *this; + } + + BaseDatabaseException::~BaseDatabaseException() throw() + { + if (this->message != NULL) + { + delete[] this->message; + this->message = NULL; + } + } + + const char* BaseDatabaseException::what() const throw() + { + return this->message; + } + + DatabaseInitializationError::DatabaseInitializationError(const char* message) throw() + : BaseDatabaseException(message) + { + } + + DatabaseInitializationError::DatabaseInitializationError(const DatabaseInitializationError& source) throw() + : BaseDatabaseException(source) + { + } + + DatabaseScriptCompilationError::DatabaseScriptCompilationError(const char* message) throw() + : BaseDatabaseException(message) + { + } + + DatabaseScriptCompilationError::DatabaseScriptCompilationError(const DatabaseScriptCompilationError& source) throw() + : BaseDatabaseException(source) + { + } + + DatabaseScriptExecutionError::DatabaseScriptExecutionError(const char* message) throw() + : BaseDatabaseException(message) + { + } + + DatabaseScriptExecutionError::DatabaseScriptExecutionError(const DatabaseScriptExecutionError& source) throw() + : BaseDatabaseException(source) + { + } + + DatabaseScriptLogicalError::DatabaseScriptLogicalError(const char* message) throw() + : BaseDatabaseException(message) + { + } + + DatabaseScriptLogicalError::DatabaseScriptLogicalError(const DatabaseScriptLogicalError& source) throw() + : BaseDatabaseException(source) + { + } +} diff --git a/libtocc/src/libtocc/database/database_exceptions.h b/libtocc/src/libtocc/database/database_exceptions.h new file mode 100644 index 0000000..943f005 --- /dev/null +++ b/libtocc/src/libtocc/database/database_exceptions.h @@ -0,0 +1,97 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#ifndef LIBTOCC_DATABASE_EXCEPTIONS_H_INCLUDED +#define LIBTOCC_DATABASE_EXCEPTIONS_H_INCLUDED + +/* + * Defines exceptions related to database layer. + */ + + +#include "libtocc/common/base_exception.h" + +namespace libtocc +{ + /* + * Base class of all the errors related to database layer. + */ + class BaseDatabaseException : public BaseException + { + public: + BaseDatabaseException(const char* message) throw(); + + BaseDatabaseException(const BaseDatabaseException& source) throw(); + + BaseDatabaseException& operator=(const BaseDatabaseException& source) throw(); + + virtual ~BaseDatabaseException() throw(); + + virtual const char* what() const throw(); + + private: + char* message; + }; + + /* + * Raises when any error occur during the initialization of the database. + */ + class DatabaseInitializationError : public BaseDatabaseException + { + public: + DatabaseInitializationError(const char* message) throw(); + + DatabaseInitializationError(const DatabaseInitializationError& source) throw(); + }; + + /* + * Raises if any error happens during the compilation of a database script. + */ + class DatabaseScriptCompilationError : public BaseDatabaseException + { + public: + DatabaseScriptCompilationError(const char* message) throw(); + + DatabaseScriptCompilationError(const DatabaseScriptCompilationError& source) throw(); + }; + + /* + * Raises if error occurs when executing a database script. + */ + class DatabaseScriptExecutionError : public BaseDatabaseException + { + public: + DatabaseScriptExecutionError(const char* message) throw(); + + DatabaseScriptExecutionError(const DatabaseScriptExecutionError& source) throw(); + }; + + /* + * Raises if any logical error happened in database. i.e. a file ID + * not found. + */ + class DatabaseScriptLogicalError : public BaseDatabaseException + { + public: + DatabaseScriptLogicalError(const char* message) throw(); + + DatabaseScriptLogicalError(const DatabaseScriptLogicalError& source) throw(); + }; +} + +#endif /* LIBTOCC_DATABASE_EXCEPTIONS_H_INCLUDED */ diff --git a/libtocc/src/libtocc/database/expr_exceptions.cpp b/libtocc/src/libtocc/database/expr_exceptions.cpp new file mode 100644 index 0000000..4639f4f --- /dev/null +++ b/libtocc/src/libtocc/database/expr_exceptions.cpp @@ -0,0 +1,43 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#include "libtocc/common/expr_exceptions.h" + +namespace libtocc +{ + +BaseExprException::BaseExprException(const char* message) throw() +{ + this->message = message; +} + +BaseExprException::~BaseExprException() throw() +{ +} + +const char* BaseExprException::what() const throw() +{ + return this->message; +} + +ExprCompilerError::ExprCompilerError(const char* message) throw() + : BaseExprException(message) +{ +} + +} diff --git a/libtocc/src/libtocc/database/expr_exceptions.h b/libtocc/src/libtocc/database/expr_exceptions.h new file mode 100644 index 0000000..626c0d2 --- /dev/null +++ b/libtocc/src/libtocc/database/expr_exceptions.h @@ -0,0 +1,53 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#ifndef LIBTOCC_EXPR_EXCEPTIONS_H_INCLUDED +#define LIBTOCC_EXPR_EXCEPTIONS_H_INCLUDED + +#include "libtocc/common/base_exception.h" + +namespace libtocc +{ + + /* + * Base class of all the errors related to expressions. + */ + class BaseExprException : public BaseException + { + public: + BaseExprException(const char* message) throw(); + + virtual ~BaseExprException() throw(); + + virtual const char* what() const throw(); + + private: + const char* message; + }; + + /* + * Raises if any errors occur during the compilation of expressions. + */ + class ExprCompilerError : public BaseExprException + { + public: + ExprCompilerError(const char* message) throw(); + }; +} + +#endif /* LIBTOCC_EXPR_EXCEPTIONS_H_INCLUDED */ diff --git a/libtocc/src/libtocc/database/file_system_exceptions.cpp b/libtocc/src/libtocc/database/file_system_exceptions.cpp new file mode 100644 index 0000000..1f13e4e --- /dev/null +++ b/libtocc/src/libtocc/database/file_system_exceptions.cpp @@ -0,0 +1,204 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#include "libtocc/common/file_system_exceptions.h" +//#ifdef _MSC_VER +#pragma warning(disable: 4996) +//#endif + +#include +#include // For `strerror'. +#include + + +namespace libtocc +{ + BaseFileSystemException::BaseFileSystemException(int err_no) throw() + { + this->err_no = err_no; + } + + BaseFileSystemException::~BaseFileSystemException() throw() + { + } + + const char* BaseFileSystemException::what() const throw() + { + return strerror(this->err_no); + } + + int BaseFileSystemException::get_errno() + { + return this->err_no; + } + + InsufficientSpaceError::InsufficientSpaceError() throw() + : BaseFileSystemException(ENOSPC) + { + } + + XAttrsAreNotSupportedError::XAttrsAreNotSupportedError() throw() + : BaseFileSystemException(ENOTSUP) + { + } + + AccessDeniedError::AccessDeniedError(const char* file_path) throw() + : BaseFileSystemException(EACCES) + { + this->file_path = file_path; + } + + AccessDeniedError::~AccessDeniedError() throw() + { + } + + const char* AccessDeniedError::what() const throw() + { + std::string result(strerror(this->err_no)); + result += " ["; + result += this->file_path; + result += "]"; + return result.c_str(); + } + + BadFDError::BadFDError(const char* file_path) throw() + : BaseFileSystemException(EBADF) + { + this->file_path = file_path; + } + + BadFDError::~BadFDError() throw() + { + } + + const char* BadFDError::what() const throw() + { + std::string result(strerror(this->err_no)); + result += " ["; + result += this->file_path; + result += "]"; + return result.c_str(); + } + + BadAddressError::BadAddressError(const char* file_path) throw() + : BaseFileSystemException(EFAULT) + { + this->file_path = file_path; + } + + BadAddressError::~BadAddressError() throw() + { + } + + const char* BadAddressError::what() const throw() + { + std::string result(strerror(this->err_no)); + result += " ["; + result += this->file_path; + result += "]"; + return result.c_str(); + } + + InfinitLinkLoopError::InfinitLinkLoopError(const char* file_path) throw() + : BaseFileSystemException(ELOOP) + { + this->file_path = file_path; + } + + InfinitLinkLoopError::~InfinitLinkLoopError() throw() + { + } + + const char* InfinitLinkLoopError::what() const throw() + { + std::string result(strerror(this->err_no)); + result += " ["; + result += this->file_path; + result += "]"; + return result.c_str(); + } + + TooLongPathError::TooLongPathError() throw() + : BaseFileSystemException(ENAMETOOLONG) + { + } + + BadPathError::BadPathError(const char* file_path) throw() + : BaseFileSystemException(ENOENT) + { + this->file_path = file_path; + } + + BadPathError::~BadPathError() throw() + { + } + + const char* BadPathError::what() const throw() + { + std::string result(strerror(this->err_no)); + result += " ["; + result += this->file_path; + result += "]"; + return result.c_str(); + } + + OutOfMemoryError::OutOfMemoryError() throw() + : BaseFileSystemException(ENOMEM) + { + } + + NotADirectoryError::NotADirectoryError() throw() + : BaseFileSystemException(ENOTDIR) + { + } + + MaxOpenFilesReachedError::MaxOpenFilesReachedError() throw() + : BaseFileSystemException(EMFILE) + { + } + + SizeOfBufferIsTooSmallError::SizeOfBufferIsTooSmallError(const char* file_path) throw() + : BaseFileSystemException(ERANGE) + { + this->file_path = file_path; + } + + SizeOfBufferIsTooSmallError::~SizeOfBufferIsTooSmallError() throw() + { + } + + const char* SizeOfBufferIsTooSmallError::what() const throw() + { + std::string result(strerror(this->err_no)); + result += " ["; + result += this->file_path; + result += "]"; + return result.c_str(); + } + + ReadOnlyFileSystemError::ReadOnlyFileSystemError() throw() + : BaseFileSystemException(EROFS) + { + } + + OtherFileSystemError::OtherFileSystemError(int err_no) throw() + : BaseFileSystemException(err_no) + { + } + +}; diff --git a/libtocc/src/libtocc/database/file_system_exceptions.h b/libtocc/src/libtocc/database/file_system_exceptions.h new file mode 100644 index 0000000..949a3cc --- /dev/null +++ b/libtocc/src/libtocc/database/file_system_exceptions.h @@ -0,0 +1,181 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#ifndef LIBTOCC_FILE_SYSTEM_EXCEPTIONS_H_INCLUDED +#define LIBTOCC_FILE_SYSTEM_EXCEPTIONS_H_INCLUDED + +/* + * Defines exceptions related to file system layer. + */ + +#include "libtocc/common/base_exception.h" + +namespace libtocc +{ + + /* + * Base class for all exceptions related to File System layer. + */ + class BaseFileSystemException : public BaseException + { + public: + BaseFileSystemException(int err_no) throw(); + + ~BaseFileSystemException() throw(); + + virtual const char* what() const throw(); + + int get_errno(); + + protected: + /* + * If any system error happens, this field will be set + * to the `errno'. If not, it is zero. + */ + int err_no; + }; + + class InsufficientSpaceError : public BaseFileSystemException + { + public: + InsufficientSpaceError() throw(); + }; + + class XAttrsAreNotSupportedError : public BaseFileSystemException + { + public: + XAttrsAreNotSupportedError() throw(); + }; + + class AccessDeniedError : public BaseFileSystemException + { + public: + AccessDeniedError(const char* file_path) throw(); + + ~AccessDeniedError() throw(); + + virtual const char* what() const throw(); + + private: + const char* file_path; + }; + + class BadFDError : public BaseFileSystemException + { + public: + BadFDError(const char* file_path) throw(); + + ~BadFDError() throw(); + + virtual const char* what() const throw(); + + private: + const char* file_path; + }; + + class BadAddressError : public BaseFileSystemException + { + public: + BadAddressError(const char* file_path) throw(); + + ~BadAddressError() throw(); + + virtual const char* what() const throw(); + + private: + const char* file_path; + }; + + class InfinitLinkLoopError : public BaseFileSystemException + { + public: + InfinitLinkLoopError(const char* file_path) throw(); + + ~InfinitLinkLoopError() throw(); + + virtual const char* what() const throw(); + + private: + const char* file_path; + }; + + class TooLongPathError : public BaseFileSystemException + { + public: + TooLongPathError() throw(); + }; + + class BadPathError : public BaseFileSystemException + { + public: + BadPathError(const char* file_path) throw(); + + ~BadPathError() throw(); + + virtual const char* what() const throw(); + + private: + const char* file_path; + }; + + class OutOfMemoryError : public BaseFileSystemException + { + public: + OutOfMemoryError() throw(); + }; + + class NotADirectoryError : public BaseFileSystemException + { + public: + NotADirectoryError() throw(); + }; + + class MaxOpenFilesReachedError : public BaseFileSystemException + { + public: + MaxOpenFilesReachedError() throw(); + }; + + class SizeOfBufferIsTooSmallError : public BaseFileSystemException + { + public: + SizeOfBufferIsTooSmallError(const char* file_path) throw(); + + ~SizeOfBufferIsTooSmallError() throw(); + + virtual const char* what() const throw(); + + private: + const char* file_path; + }; + + class ReadOnlyFileSystemError : public BaseFileSystemException + { + public: + ReadOnlyFileSystemError() throw(); + }; + + class OtherFileSystemError : public BaseFileSystemException + { + public: + OtherFileSystemError(int err_no) throw(); + }; + +} + +#endif /* LIBTOCC_FILE_SYSTEM_EXCEPTIONS_H_INCLUDED */ diff --git a/libtocc/src/libtocc/database/funcs.cpp b/libtocc/src/libtocc/database/funcs.cpp index 7891ae0..b4eaaa9 100644 --- a/libtocc/src/libtocc/database/funcs.cpp +++ b/libtocc/src/libtocc/database/funcs.cpp @@ -44,7 +44,7 @@ namespace libtocc return true; } // We reached end of the string. - if (*pattern == '*' and !*(pattern + 1)) + if (*pattern == '*'&& !*(pattern + 1)) { // If last character of pattern was wild card, they're matched // successfully. diff --git a/libtocc/src/libtocc/database/int_file_info.cpp b/libtocc/src/libtocc/database/int_file_info.cpp new file mode 100644 index 0000000..9160c3b --- /dev/null +++ b/libtocc/src/libtocc/database/int_file_info.cpp @@ -0,0 +1,140 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#include "libtocc/common/int_file_info.h" + +#include + + +namespace libtocc +{ + + IntFileInfo::IntFileInfo(std::string file_id) + { + this->id = file_id; + } + + IntFileInfo::IntFileInfo(std::string file_id, + std::string title, + std::string traditional_path, + std::vector tags) + { + this->id = file_id; + this->title = title; + this->traditional_path = traditional_path; + this->tags = tags; + } + + IntFileInfo::IntFileInfo(const IntFileInfo& source) + { + this->id = source.id; + this->title = source.title; + this->traditional_path = source.traditional_path; + this->tags = source.tags; + } + + std::string IntFileInfo::get_id() const + { + return this->id; + } + + void IntFileInfo::set_tags(std::vector new_tags) + { + this->tags = new_tags; + } + + void IntFileInfo::add_tag(std::string new_tag) + { + this->tags.push_back(new_tag); + } + + std::vector IntFileInfo::get_tags() const + { + return this->tags; + } + + void IntFileInfo::set_title(std::string file_title) + { + this->title = file_title; + } + + std::string IntFileInfo::get_title() const + { + return this->title; + } + + void IntFileInfo::set_traditional_path(std::string path) + { + this->traditional_path = path; + } + + std::string IntFileInfo::get_traditional_path() const + { + return this->traditional_path; + } + + std::string IntFileInfo::to_string() const + { + std::stringstream result_stream; + result_stream << "{" << std::endl; + result_stream << " file_id: " << this->get_id() << std::endl; + result_stream << " title: " << this->get_title() << std::endl; + result_stream << " traditional_path: " << this->get_traditional_path(); + result_stream << std::endl; + + // Writing tags. + result_stream << " tags: ["; + std::vector tags = this->get_tags(); + std::vector::iterator iterator = tags.begin(); + for (; iterator != tags.end(); ++iterator) + { + result_stream << *iterator << ", "; + } + result_stream << "]" << std::endl; + + result_stream << "}"; + + return result_stream.str(); + } + + /* + * Overrided operator for std::ostream. + * So it can be used like: + * std::cout << file_info; + */ + std::ostream& operator<<(std::ostream& stream, + const IntFileInfo& file_info) + { + return stream << file_info.to_string(); + } + + IntFileInfo& IntFileInfo::operator=(const IntFileInfo& source) + { + if (this == &source) + { + return *this; + } + + this->id = source.id; + this->title = source.title; + this->traditional_path = source.traditional_path; + this->tags = source.tags; + + return *this; + } +} diff --git a/libtocc/src/libtocc/database/int_file_info.h b/libtocc/src/libtocc/database/int_file_info.h new file mode 100644 index 0000000..21fbe2a --- /dev/null +++ b/libtocc/src/libtocc/database/int_file_info.h @@ -0,0 +1,119 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#ifndef LIBTOCC_INT_FILE_INFO_H_INCLUDED +#define LIBTOCC_INT_FILE_INFO_H_INCLUDED + +/* + * Defines two classes: One is Internal File Info, and other one is + * Internal File Info Collection which is a collection of the first one. + */ + +#include +#include + +namespace libtocc +{ + + /* + * Keeps information about a file. + * This class is internal and only accessible inside the library. + * Interface methods should use FileInfo class. + */ + class IntFileInfo + { + public: + IntFileInfo(std::string file_id); + + IntFileInfo(std::string file_id, + std::string title, + std::string traditional_path, + std::vector tags); + + /* + * Copy constructor. + */ + IntFileInfo(const IntFileInfo& source); + + /* + * Gets ID of the file. + */ + std::string get_id() const; + + /* + * Sets a list of tags to file. + * Note that it replace old ones. + */ + void set_tags(std::vector new_tags); + + /* + * Add a single tag to file. + */ + void add_tag(std::string new_tag); + + /* + * Gets all the tags of this file. + */ + std::vector get_tags() const; + + /* + * Sets a title for the file. + */ + void set_title(std::string file_title); + + /* + * Gets title of the file. + */ + std::string get_title() const; + + /* + * Sets traditional path for the file. + */ + void set_traditional_path(std::string path); + + /* + * Gets traditional path of the file. + */ + std::string get_traditional_path() const; + + /* + * Returns a string representation of the file. + */ + std::string to_string() const; + + /* + * Overrided operator for std::ostream. + * So it can be used like: + * std::cout << file_info; + */ + friend std::ostream& operator<<(std::ostream& stream, const IntFileInfo& file_info); + + /* + * Assignment operator. + */ + IntFileInfo& operator=(const IntFileInfo& source); + + private: + std::string id; + std::vector tags; + std::string title; + std::string traditional_path; + }; +} + +#endif /* LIBTOCC_INT_FILE_INFO_H_INCLUDED */ diff --git a/libtocc/src/libtocc/database/runtime_exceptions.h b/libtocc/src/libtocc/database/runtime_exceptions.h new file mode 100644 index 0000000..fda396e --- /dev/null +++ b/libtocc/src/libtocc/database/runtime_exceptions.h @@ -0,0 +1,50 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#ifndef LIBTOCC_RUNTIME_EXCEPTIONS_H_INCLUDED +#define LIBTOCC_RUNTIME_EXCEPTIONS_H_INCLUDED + +#include "libtocc/common/base_exception.h" + +namespace libtocc +{ + class InvalidArgumentError : public BaseException + { + public: + InvalidArgumentError(const char* message) throw() + { + this->message = message; + } + + virtual ~InvalidArgumentError() throw() + { + } + + virtual const char* what() const throw() + { + return this->message; + } + + private: + const char* message; + }; + +} + + +#endif /* LIBTOCC_RUNTIME_EXCEPTIONS_H_INCLUDED */ diff --git a/libtocc/src/libtocc/file_system/file_manager.cpp b/libtocc/src/libtocc/file_system/file_manager.cpp index 209ea19..199bae5 100644 --- a/libtocc/src/libtocc/file_system/file_manager.cpp +++ b/libtocc/src/libtocc/file_system/file_manager.cpp @@ -16,29 +16,106 @@ * along with Tocc. If not, see . */ + #include "libtocc/file_system/file_manager.h" +#ifdef _MSC_VER +#pragma warning(disable: 4996) +#include "unistdx.h" +#else #include +#endif #include #include #include #include #include +#ifdef _MSC_VER +#include +#endif #ifdef HAVE_SENDFILE // check if sendfile is available #include #endif #include "libtocc/common/runtime_exceptions.h" -#include "libtocc/file_system/helpers.cpp" - +#include "libtocc/file_system/helpers.h" +#include "libtocc/common/file_system_exceptions.h" namespace libtocc { + /* + * Throws and exception according to the errno. + * + * @param errno: System's errno. + * @param file_path: (optional) path of the file that this + * error is happened for. + */ + void handle_errno(int err_no, std::string file_path = "") + { +#ifdef _MSC_VER + if (err_no == ENOSPC) +#else + if (err_no == ENOSPC || err_no == EDQUOT) +#endif + { + throw InsufficientSpaceError(); + } + if (err_no == ENOTSUP) + { + throw XAttrsAreNotSupportedError(); + } + if (err_no == EACCES) + { + throw AccessDeniedError(file_path.c_str()); + } + if (err_no == EBADF) + { + throw BadFDError(file_path.c_str()); + } + if (err_no == EFAULT) + { + throw BadAddressError(file_path.c_str()); + } + if (err_no == ELOOP) + { + throw InfinitLinkLoopError(file_path.c_str()); + } + if (err_no == ENAMETOOLONG) + { + throw TooLongPathError(); + } + if (err_no == ENOENT) + { + throw BadPathError(file_path.c_str()); + } + if (err_no == ENOMEM) + { + throw OutOfMemoryError(); + } + if (err_no == ENOTDIR) + { + throw NotADirectoryError(); + } + if (err_no == ERANGE) + { + throw SizeOfBufferIsTooSmallError(file_path.c_str()); + } + if (err_no == EROFS) + { + throw ReadOnlyFileSystemError(); + } + if (err_no == EMFILE) + { + throw MaxOpenFilesReachedError(); + } + // If it was none of the above. + throw OtherFileSystemError(err_no); + } /* * Mode for creating files and directories. */ - const mode_t NORMAL_MODE = S_IRWXU | S_IRGRP | S_IROTH; + const int NORMAL_MODE = S_IRWXU | S_IRGRP | S_IROTH; FileManager::FileManager(std::string base_path) { @@ -51,7 +128,11 @@ namespace libtocc ensure_path_exists(id); // Creating the file. +#ifdef _MSC_VER + int creat_result = _creat(id_to_file_path(id).c_str(), _S_IREAD | _S_IWRITE); +#else int creat_result = creat(id_to_file_path(id).c_str(), NORMAL_MODE); +#endif if (creat_result < 0) { handle_errno(errno, id); @@ -131,13 +212,13 @@ namespace libtocc // we don't have sendfile, so we'll use read and write while ((size = read(source, buf, BUFSIZ)) > 0) { - ssize_t write_result = write(dest, buf, size); + long int write_result = write(dest, buf, size); - if (write_result < 0) - { + if (write_result < 0) + { // An error occurred while writing to file. - handle_errno(errno, source_path); - } + handle_errno(errno, source_path); + } } #else off_t offset = 0; @@ -163,8 +244,11 @@ namespace libtocc // only the last directory should be created. So, first // we try that. std::string dir_path = id_to_dir_path(id); +#ifdef _MSC_VER + int mkdir_result = _mkdir(dir_path.c_str()); +#else int mkdir_result = mkdir(dir_path.c_str(), NORMAL_MODE); - +#endif if (mkdir_result >= 0) { // Path created sucessfully. No need to do anything else. @@ -201,7 +285,11 @@ namespace libtocc void FileManager::create_dir(std::string path) { +#ifdef _MSC_VER + int mkdir_result = _mkdir(path.c_str()); +#else int mkdir_result = mkdir(path.c_str(), NORMAL_MODE); +#endif if (mkdir_result < 0) { if (errno != EEXIST && errno != ENOENT) diff --git a/libtocc/src/libtocc/file_system/file_manager.cpp.bak b/libtocc/src/libtocc/file_system/file_manager.cpp.bak new file mode 100644 index 0000000..5727d94 --- /dev/null +++ b/libtocc/src/libtocc/file_system/file_manager.cpp.bak @@ -0,0 +1,332 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#ifdef _MSC_VER +#pragma warning(disable: 4996) +#include "unistdx.h" +#else +#include +#endif +#include +#include +#include +#include +#include +#ifdef _MSC_VER +#include +#endif +#ifdef HAVE_SENDFILE // check if sendfile is available + #include +#endif + +#include "libtocc/common/runtime_exceptions.h" +#include "libtocc/file_system/helpers.h" +#include "libtocc/common/file_system_exceptions.h" +#include "libtocc/file_system/file_manager.h" + +namespace libtocc +{ + /* + * Throws and exception according to the errno. + * + * @param errno: System's errno. + * @param file_path: (optional) path of the file that this + * error is happened for. + */ + void handle_errno(int err_no, std::string file_path = "") + { +#ifdef _MSC_VER + if (err_no == ENOSPC) +#else + if (err_no == ENOSPC || err_no == EDQUOT) +#endif + { + throw InsufficientSpaceError(); + } + if (err_no == ENOTSUP) + { + throw XAttrsAreNotSupportedError(); + } + if (err_no == EACCES) + { + throw AccessDeniedError(file_path.c_str()); + } + if (err_no == EBADF) + { + throw BadFDError(file_path.c_str()); + } + if (err_no == EFAULT) + { + throw BadAddressError(file_path.c_str()); + } + if (err_no == ELOOP) + { + throw InfinitLinkLoopError(file_path.c_str()); + } + if (err_no == ENAMETOOLONG) + { + throw TooLongPathError(); + } + if (err_no == ENOENT) + { + throw BadPathError(file_path.c_str()); + } + if (err_no == ENOMEM) + { + throw OutOfMemoryError(); + } + if (err_no == ENOTDIR) + { + throw NotADirectoryError(); + } + if (err_no == ERANGE) + { + throw SizeOfBufferIsTooSmallError(file_path.c_str()); + } + if (err_no == EROFS) + { + throw ReadOnlyFileSystemError(); + } + if (err_no == EMFILE) + { + throw MaxOpenFilesReachedError(); + } + // If it was none of the above. + throw OtherFileSystemError(err_no); + } + + /* + * Mode for creating files and directories. + */ + const int NORMAL_MODE = S_IRWXU | S_IRGRP | S_IROTH; + + FileManager::FileManager(std::string base_path) + { + this->base_path = base_path; + } + + int FileManager::create(std::string id) + { + // Ensuring path exists. It will create it if it is not. + ensure_path_exists(id); + + // Creating the file. +#ifdef _MSC_VER + int creat_result = _creat(id_to_file_path(id).c_str(), _S_IREAD | _S_IWRITE); +#else + int creat_result = creat(id_to_file_path(id).c_str(), NORMAL_MODE); +#endif + if (creat_result < 0) + { + handle_errno(errno, id); + } + + return creat_result; // Which is the file descriptor. + } + + int FileManager::open_file(std::string id, char mode) + { + std::string file_path = id_to_file_path(id); + + // Making flags for system's `open' method. + int open_flags; + if (mode == 'r') + { + open_flags = O_RDONLY; + } + else if (mode == 'w') + { + open_flags = O_WRONLY | O_TRUNC; + } + else if (mode == 'a') + { + open_flags = O_WRONLY; + } + else + { + throw InvalidArgumentError("Inavlid mode for openning file."); + } + + int fd = open(file_path.c_str(), open_flags); + + if (fd < 0) + { + handle_errno(errno, file_path); + } + + return fd; + } + + void FileManager::remove(std::string file_id) + { + // I used "unlink" not "remove", because I'm sure path is + // referring to a file, not a directory or something. + int unlink_result = unlink(id_to_file_path(file_id).c_str()); + + if (unlink_result < 0) + { + if (errno != ENOENT) + { + // If error is something other than "path does not exists". + handle_errno(errno, file_id); + } + } + } + + void FileManager::copy(std::string source_path, std::string file_id) + { + + // TODO: Maybe we should use `st_blksize' of the file attributes instead + // of the BUFSIZ. That's the optimal value, but we need to read the + // attribute from the file, before starting. + + char buf[BUFSIZ]; // BUFSIZ is defined in . + size_t size; + + int dest = create(file_id); + int source = open(source_path.c_str(), O_RDONLY); + if(source == -1) + { + handle_errno(errno, source_path); + } + + // `sendfile' is a lot faster. We use it if available. + #ifndef HAVE_SENDFILE + // we don't have sendfile, so we'll use read and write + while ((size = _read(source, buf, BUFSIZ)) > 0) + { + long int write_result = _write(dest, buf, size); + + if (write_result < 0) + { + // An error occurred while writing to file. + handle_errno(errno, source_path); + } + } + #else + off_t offset = 0; + struct stat stat_buf; + // Stat the source file to obtain its size. + fstat (source, &stat_buf); + // Send the file with sendfile + sendfile(dest, source, &offset, stat_buf.st_size); + #endif + + close(source); + close(dest); + } + + std::string FileManager::get_physical_path(std::string file_id) + { + return id_to_file_path(file_id); + } + + void FileManager::ensure_path_exists(std::string id) + { + // There's a big chance that path is already exists or + // only the last directory should be created. So, first + // we try that. + std::string dir_path = id_to_dir_path(id); +#ifdef _MSC_VER + int mkdir_result = _mkdir(dir_path.c_str()); +#else + int mkdir_result = mkdir(dir_path.c_str(), NORMAL_MODE); +#endif + if (mkdir_result >= 0) + { + // Path created sucessfully. No need to do anything else. + return; + } + else + { + if (errno == EEXIST) + { + // Path is already exists. Nothing else to do. + return; + } + if (errno != ENOENT) + { + // If error is something other than "path already exists" + // or "part of the path doesn't exists", throw an exception. + handle_errno(errno, dir_path); + } + } + + // Creating the path recursively. + // Note: I know that I'm duplicating the code, but its faster than + // splitting the path. + std::string path_to_create(this->base_path); + + path_to_create += "/"; + path_to_create += id.substr(0, 1) + "/"; + create_dir(path_to_create); + path_to_create += id.substr(1, 2) + "/"; + create_dir(path_to_create); + path_to_create += id.substr(3, 2) + "/"; + create_dir(path_to_create); + } + + void FileManager::create_dir(std::string path) + { +#ifdef _MSC_VER + int mkdir_result = _mkdir(path.c_str()); +#else + int mkdir_result = mkdir(path.c_str(), NORMAL_MODE); +#endif + if (mkdir_result < 0) + { + if (errno != EEXIST && errno != ENOENT) + { + // If error wasn't "path already exists" or "part of the path + // already exists", throw an exception. + handle_errno(errno, path); + } + } + } + + std::string FileManager::id_to_dir_path(std::string id) + { + // TODO: Raise exception if ID is not valid (e.g. its length is incorrect.) + + std::string result(this->base_path); + + if (result.at(result.length() - 1) != '/') + { + result += "/"; + } + + result += id.substr(0, 1); + result += "/"; + result += id.substr(1, 2); + result += "/"; + result += id.substr(3, 2); + result += "/"; + + return result; + } + + std::string FileManager::id_to_file_path(std::string id) + { + std::string result(id_to_dir_path(id)); + + result += id.substr(5, 2); + + return result; + } + +}; diff --git a/libtocc/src/libtocc/file_system/helpers.cpp b/libtocc/src/libtocc/file_system/helpers.cpp index eb9d6aa..f1363c3 100644 --- a/libtocc/src/libtocc/file_system/helpers.cpp +++ b/libtocc/src/libtocc/file_system/helpers.cpp @@ -21,76 +21,9 @@ */ #include - +#include "libtocc/file_system/helpers.h" #include "libtocc/common/file_system_exceptions.h" #include -namespace libtocc -{ - - /* - * Throws and exception according to the errno. - * - * @param errno: System's errno. - * @param file_path: (optional) path of the file that this - * error is happened for. - */ - void handle_errno(int err_no, std::string file_path="") - { - if (err_no == ENOSPC || err_no == EDQUOT) - { - throw InsufficientSpaceError(); - } - if (err_no == ENOTSUP) - { - throw XAttrsAreNotSupportedError(); - } - if (err_no == EACCES) - { - throw AccessDeniedError(file_path.c_str()); - } - if (err_no == EBADF) - { - throw BadFDError(file_path.c_str()); - } - if (err_no == EFAULT) - { - throw BadAddressError(file_path.c_str()); - } - if (err_no == ELOOP) - { - throw InfinitLinkLoopError(file_path.c_str()); - } - if (err_no == ENAMETOOLONG) - { - throw TooLongPathError(); - } - if (err_no == ENOENT) - { - throw BadPathError(file_path.c_str()); - } - if (err_no == ENOMEM) - { - throw OutOfMemoryError(); - } - if (err_no == ENOTDIR) - { - throw NotADirectoryError(); - } - if (err_no == ERANGE) - { - throw SizeOfBufferIsTooSmallError(file_path.c_str()); - } - if (err_no == EROFS) - { - throw ReadOnlyFileSystemError(); - } - if (err_no == EMFILE) - { - throw MaxOpenFilesReachedError(); - } - // If it was none of the above. - throw OtherFileSystemError(err_no); - } +//namespace libtocc -} diff --git a/libtocc/src/libtocc/file_system/helpers.h b/libtocc/src/libtocc/file_system/helpers.h new file mode 100644 index 0000000..d009228 --- /dev/null +++ b/libtocc/src/libtocc/file_system/helpers.h @@ -0,0 +1,28 @@ +/* + * This file is part of Tocc. (see ) + * Copyright (C) 2013, 2014, Aidin Gharibnavaz + * + * Tocc 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 3 of the License, or + * (at your option) any later version. + * + * Tocc 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 Tocc. If not, see . + */ + +#pragma once + +#ifndef LIBTOCC_HELPERS_H_INCLUDED +#define LIBTOCC_HELPERS_INCLUDED + +#include + +void handle_errno(int err_no, std::string file_path=""); + +#endif \ No newline at end of file diff --git a/libtocc/src/libtocc/front_end/manager.cpp b/libtocc/src/libtocc/front_end/manager.cpp index 98de4d3..cf51f49 100644 --- a/libtocc/src/libtocc/front_end/manager.cpp +++ b/libtocc/src/libtocc/front_end/manager.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "libtocc/database/database.h" #include "libtocc/file_system/file_manager.h" @@ -34,7 +35,7 @@ namespace libtocc * Name of the database file, which should be existed in the root * of the path. */ - const std::string DATABASE_FILE = "TOCCFILES.DB"; + //const std::string DATABASE_FILE = "TOCCFILE"; class Manager::PrivateData { @@ -71,7 +72,7 @@ namespace libtocc Manager::Manager(const char* base_path) { std::string database_path(base_path); - database_path += "/"; + // database_path += "/"; database_path += DATABASE_FILE; Database* database = new Database(database_path); diff --git a/libtocc/src/libtocc/front_end/manager.h b/libtocc/src/libtocc/front_end/manager.h index d5763a8..510a862 100644 --- a/libtocc/src/libtocc/front_end/manager.h +++ b/libtocc/src/libtocc/front_end/manager.h @@ -23,7 +23,6 @@ #include "libtocc/front_end/tag_statistics.h" #include "libtocc/exprs/query.h" - namespace libtocc { /* @@ -256,7 +255,7 @@ namespace libtocc */ void set_title(const char* file_id, const char* new_title); - private: +// private: /* * Keeps the private data, and hides it from the client. */ diff --git a/libtocc/src/libtocc/utilities/file_info_converter.cpp b/libtocc/src/libtocc/utilities/file_info_converter.cpp index 7a37c2c..98e8851 100644 --- a/libtocc/src/libtocc/utilities/file_info_converter.cpp +++ b/libtocc/src/libtocc/utilities/file_info_converter.cpp @@ -67,7 +67,7 @@ namespace libtocc } // File info collection with reserved size. - FileInfoCollection result(internal_file_infos.size()); + FileInfoCollection result((int) internal_file_infos.size()); std::vector::iterator iterator = internal_file_infos.begin(); for (; iterator != internal_file_infos.end(); ++iterator) @@ -92,20 +92,27 @@ namespace libtocc return tags_vector; } - TagsCollection vector_to_tags(const std::vector* vector) + TagsCollection vector_to_tags(const std::vector* const vector) { if (vector->empty()) { return TagsCollection(); } - const char* tags[vector->size()]; + const size_t sz = vector->size(); + + char c; + TagsCollection tc = TagsCollection(); + int size1 = sizeof &c; + char** tags = (char**) malloc(size1 * sz); for (unsigned int i = 0; i < vector->size(); ++i) { - tags[i] = (*vector)[i].c_str(); + tags[i] = (char *)(*vector)[i].c_str(); } - return TagsCollection(tags, vector->size()); + tc = TagsCollection((const char **)tags, (int) vector->size()); + free(tags); + return tc; } std::vector file_info_collection_to_vector_ids(const FileInfoCollection& file_info_collection) diff --git a/libtocc/src/libtocc/utilities/file_utils.cpp b/libtocc/src/libtocc/utilities/file_utils.cpp index 833c47a..b014754 100644 --- a/libtocc/src/libtocc/utilities/file_utils.cpp +++ b/libtocc/src/libtocc/utilities/file_utils.cpp @@ -16,6 +16,11 @@ * along with Tocc. If not, see . */ +#ifdef _MSC_VER +#include +#endif + +#include #include"libtocc/utilities/file_utils.h" namespace libtocc @@ -23,17 +28,20 @@ namespace libtocc std::string get_filename_from_path(std::string path) { std::string filename; - - //extract the file from path +#ifdef _MSC_VER + int pos1 = path.rfind("/"); + int pos2 = path.rfind("\\"); + int last_slash_index = max(pos1, pos2); +#else int last_slash_index = path.rfind("/"); - - if(last_slash_index != std::string::npos) +#endif + if (last_slash_index != std::string::npos) { filename = path.substr(last_slash_index + 1, path.length()); } else { - if(path.length()!=0) + if (path.length() != 0) { filename = path; } @@ -42,21 +50,37 @@ namespace libtocc return filename; } +#ifdef _MSC_VER + bool DirectoryExists(const char* dirName) + { + DWORD attribs = ::GetFileAttributesA(dirName); + if (attribs == INVALID_FILE_ATTRIBUTES) { + return false; + } + return (attribs & FILE_ATTRIBUTE_DIRECTORY); + } + + bool is_path_parent_exists(std::string database_path) + { + int pos1 = database_path.rfind("/"); + int pos2 = database_path.rfind("\\"); + int pos = max(pos1, pos2); + std::string base_path = database_path.substr(0, pos); + return DirectoryExists(base_path.c_str()); + } +#else bool is_path_parent_exists(std::string database_path) { DIR* directory_ptr = NULL; - int pos = 0; - - pos = database_path.rfind('/'); + int pos = database_path.rfind("/"); std::string base_path = database_path.substr(0, pos); directory_ptr = opendir(base_path.c_str()); - if(directory_ptr == NULL) + if (directory_ptr == NULL) { return false; } - closedir(directory_ptr); return true; } - +#endif } diff --git a/libtocc/src/libtocc/utilities/file_utils.h b/libtocc/src/libtocc/utilities/file_utils.h index e11adab..08ed5bb 100644 --- a/libtocc/src/libtocc/utilities/file_utils.h +++ b/libtocc/src/libtocc/utilities/file_utils.h @@ -20,8 +20,10 @@ #define LIBTOCC_FILE_FILE_UTILS_H_INCLUDED #include +#ifdef _MSC_VER +#else #include - +#endif namespace libtocc { /* diff --git a/libtocc/src/unistdx.h b/libtocc/src/unistdx.h new file mode 100644 index 0000000..4a5af1a --- /dev/null +++ b/libtocc/src/unistdx.h @@ -0,0 +1,319 @@ +/* +MIT License +Copyright (c) 2019 win32ports +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#ifndef __UNISTD_H_17CD2BD1_839A_4E25_97C7_DE9544B8B59C__ +#define __UNISTD_H_17CD2BD1_839A_4E25_97C7_DE9544B8B59C__ + +#ifndef _WIN32 + +#pragma message("this unistd.h implementation is for Windows only!") + +#else /* _WIN32 */ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef _INC_IO +#include /* _access() */ +#endif /* _INC_IO */ + +#ifndef _INC_DIRECT +#include /* _chdir() */ +#endif /* _INC_DIRECT */ + +#ifndef _INC_PROCESS +#include /* _execl() */ +#endif /* _INC_PROCESS */ + +#include /* */ + +#ifndef access +#define access _access +#endif /* access */ + +#ifndef R_OK +#define R_OK 04 +#endif /* R_OK */ + +#ifndef W_OK +#define W_OK 02 +#endif /* W_OK */ + +#ifndef X_OK +#define X_OK R_OK +#endif /* X_OK */ + +#ifndef F_OK +#define F_OK 00 +#endif /* F_OK */ + +#ifndef chdir +#define chdir _chdir +#endif /* chdir */ + +#ifndef close +#define close _close +#endif /* close */ + +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif /* STDIN_FILENO */ + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif /* STDOUT_FILENO */ + +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif /* STDERR_FILENO */ + +#ifndef dup +#define dup _dup +#endif /* dup */ + +#ifndef dup2 +#define dup2 _dup2 +#endif /* dup2 */ + +#ifndef execl +#define execl _execl +#endif /* execl */ + +#ifndef execle +#define execle _execle +#endif /* execle */ + +#ifndef execlp +#define execlp _execlp +#endif /* execlp */ + +#ifndef execp +#define execp _execp +#endif /* execp */ + +#ifndef execpe +#define execpe _execpe +#endif /* execpe */ + +#ifndef execpp +#define execpp _execpp +#endif /* execpp */ + +#ifndef rmdir +#define rmdir _rmdir +#endif /* rmdir */ +#ifndef unlink +#define unlink _unlink +#endif /* unlink */ + +//#ifndef write +//#define write _write +//#endif + +/* permission bits below must be defined in sys/stat.h, but MSVC lacks them */ + +#ifndef S_IRWXU +#define S_IRWXU 0700 +#endif /* S_IRWXU */ + +#ifndef S_IRUSR +#define S_IRUSR 0400 +#endif /* S_IRUSR */ + +#ifndef S_IWUSR +#define S_IWUSR 0200 +#endif /* S_IWUSR */ + +#ifndef S_IXUSR +#define S_IXUSR 0100 +#endif /* S_IXUSR */ + +#ifndef S_IRWXG +#define S_IRWXG 070 +#endif /* S_IRWXG */ + +#ifndef S_IRGRP +#define S_IRGRP 040 +#endif /* S_IRGRP */ + +#ifndef S_IWGRP +#define S_IWGRP 020 +#endif /* S_IWGRP */ + +#ifndef S_IXGRP +#define S_IXGRP 010 +#endif /* S_IXGRP */ + +#ifndef S_IRWXO +#define S_IRWXO 07 +#endif /* S_IRWXO */ + +#ifndef S_IROTH +#define S_IROTH 04 +#endif /* S_IROTH */ + +#ifndef S_IWOTH +#define S_IWOTH 02 +#endif /* S_IWOTH */ + +#ifndef S_IXOTH +#define S_IXOTH 01 +#endif /* S_IXOTH */ + +#ifndef S_ISUID +#define S_ISUID 04000 +#endif /* S_ISUID */ + +#ifndef S_ISGID +#define S_ISGID 02000 +#endif /* S_ISGID */ + +#ifndef S_ISVTX +#define S_ISVTX 01000 +#endif /* S_ISVTX */ + +#ifndef S_IRWXUGO +#define S_IRWXUGO 0777 +#endif /* S_IRWXUGO */ + +#ifndef S_IALLUGO +#define S_IALLUGO 0777 +#endif /* S_IALLUGO */ + +#ifndef S_IRUGO +#define S_IRUGO 0444 +#endif /* S_IRUGO */ + +#ifndef S_IWUGO +#define S_IWUGO 0222 +#endif /* S_IWUGO */ + +#ifndef S_IXUGO +#define S_IXUGO 0111 +#endif /* S_IXUGO */ + +#ifndef _S_IFMT +#define _S_IFMT 0xF000 +#endif /* _S_IFMT */ + +#ifndef _S_IFIFO +#define _S_IFIFO 0x1000 +#endif /* _S_IFIFO */ + +#ifndef _S_IFCHR +#define _S_IFCHR 0x2000 +#endif /* _S_IFCHR */ + +#ifndef _S_IFDIR +#define _S_IFDIR 0x4000 +#endif /* _S_IFDIR */ + +#ifndef _S_IFBLK +#define _S_IFBLK 0x6000 +#endif /* _S_IFBLK */ + +#ifndef _S_IFREG +#define _S_IFREG 0x8000 +#endif /* _S_IFREG */ + +#ifndef _S_IFLNK +#define _S_IFLNK 0xA000 +#endif /* _S_IFLNK */ + +#ifndef _S_IFSOCK +#define _S_IFSOCK 0xC000 +#endif /* _S_IFSOCK */ + +#ifndef S_IFMT +#define S_IFMT _S_IFMT +#endif /* S_IFMT */ + +#ifndef S_IFIFO +#define S_IFIFO _S_IFIFO +#endif /* S_IFIFO */ + +#ifndef S_IFCHR +#define S_IFCHR _S_IFCHR +#endif /* S_IFCHR */ + +#ifndef S_IFDIR +#define S_IFDIR _S_IFDIR +#endif /* S_IFDIR */ + +#ifndef S_IFBLK +#define S_IFBLK _S_IFBLK +#endif /* S_IFBLK */ + +#ifndef S_IFREG +#define S_IFREG _S_IFREG +#endif /* S_IFREG */ + +#ifndef S_IFLNK +#define S_IFLNK _S_IFLNK +#endif /* S_IFLNK */ + +#ifndef S_IFSOCK +#define S_IFSOCK _S_IFSOCK +#endif /* S_IFSOCK */ + +#ifndef S_ISTYPE +#define S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask)) +#endif /* S_ISTYPE */ + +#ifndef S_ISFIFO +#define S_ISFIFO(mode) S_ISTYPE(mode, S_IFIFO) +#endif /* S_ISFIFO */ + +#ifndef S_ISCHR +#define S_ISCHR(mode) S_ISTYPE(mode, S_IFCHR) +#endif /* S_ISCHR */ + +#ifndef S_ISDIR +#define S_ISDIR(mode) S_ISTYPE(mode, S_IFDIR) +#endif /* S_ISDIR */ + +#ifndef S_ISBLK +#define S_ISBLK(mode) S_ISTYPE(mode, S_IFBLK) +#endif /* S_ISBLK */ + +#ifndef S_ISREG +#define S_ISREG(mode) S_ISTYPE(mode, S_IFREG) +#endif /* S_ISREG */ + +#ifndef S_ISLNK +#define S_ISLNK(mode) S_ISTYPE(mode, S_IFLNK) +#endif /* S_ISLNK */ + +#ifndef S_ISSOCK +#define S_ISSOCK(mode) S_ISTYPE(mode, S_IFSOCK) +#endif /* S_ISSOCK */ + +#define mode_t short int + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _WIN32 */ + +#endif /* __UNISTD_H_17CD2BD1_839A_4E25_97C7_DE9544B8B59C__ */ diff --git a/libtocc/tests/catch.hpp b/libtocc/tests/catch.hpp new file mode 100644 index 0000000..82313cf --- /dev/null +++ b/libtocc/tests/catch.hpp @@ -0,0 +1 @@ +#include "catch_amalgamated.hpp" \ No newline at end of file diff --git a/libtocc/tests/config b/libtocc/tests/config new file mode 100755 index 0000000..6c79c53 --- /dev/null +++ b/libtocc/tests/config @@ -0,0 +1,2 @@ +set -x +./configure CPPFLAGS="-I../src/ -I../tests" LDFLAGS="-L/usr/local/lib" CXXFLAGS="-I../src/ -I../tests" LIBS="-lcatch_amalgamated" diff --git a/libtocc/tests/database/database_basic_tests.cpp b/libtocc/tests/database/database_basic_tests.cpp index f84eac0..cbed149 100644 --- a/libtocc/tests/database/database_basic_tests.cpp +++ b/libtocc/tests/database/database_basic_tests.cpp @@ -17,19 +17,35 @@ */ #include "catch.hpp" +#include "testdb_path.hpp" #include #include +#include +#include #include "libtocc/common/int_file_info.h" #include "libtocc/database/database.h" +/* The database initializer test was moved to here because, under Windows, + * it is not executed before the database basic tests if it is in a + * different file. +*/ + + // This should be run before all the other database tests, since it's + // initialize an environment for tests. +TEST_CASE("Database_Initializer:init") +{ + std::string path = testdb_path(DATABASE_FILE); + libtocc::Database db(path.c_str()); + db.initialize(); +} + TEST_CASE("database: basic tests") { // Creating the database. - libtocc::Database db("/tmp/tocctests/tocc.test.db"); - - // Creating a file with no property. + libtocc::Database db(testdb_path(DATABASE_FILE).c_str()); + // Creating a file with no property. libtocc::IntFileInfo new_file_1 = db.create_file(); // Checking if it's OK. REQUIRE(new_file_1.get_title() == ""); @@ -38,10 +54,9 @@ TEST_CASE("database: basic tests") // Creating a file with title and traditional path. libtocc::IntFileInfo new_file_2 = - db.create_file("Title of the second file", "/old/path/"); - // Checking if it's OK. + db.create_file("Title of the second file", "/old/path"); REQUIRE(new_file_2.get_title() == "Title of the second file"); - REQUIRE(new_file_2.get_traditional_path() == "/old/path/"); + REQUIRE(new_file_2.get_traditional_path() == "/old/path"); REQUIRE(new_file_2.get_tags().size() == 0); // Creating a file with tags. @@ -53,7 +68,6 @@ TEST_CASE("database: basic tests") // Checking if it's OK. REQUIRE(new_file_3.get_title() == "First Photo"); REQUIRE(new_file_3.get_traditional_path() == ""); - std::vector file_3_tags = new_file_3.get_tags(); REQUIRE(file_3_tags.size() == 3); std::vector::iterator file_3_tags_iterator = file_3_tags.begin(); @@ -74,7 +88,7 @@ TEST_CASE("database: basic tests") libtocc::IntFileInfo fetched_file_2 = db.get(new_file_2.get_id()); // Checking if it's OK. REQUIRE(fetched_file_2.get_title() == "Title of the second file"); - REQUIRE(fetched_file_2.get_traditional_path() == "/old/path/"); + REQUIRE(fetched_file_2.get_traditional_path() == "/old/path"); REQUIRE(fetched_file_2.get_tags().size() == 0); // Fetching third file. @@ -91,5 +105,4 @@ TEST_CASE("database: basic tests") REQUIRE((*fetched_tags_iterator) == "abstract"); ++fetched_tags_iterator; REQUIRE((*fetched_tags_iterator) == "b&w"); - } diff --git a/libtocc/tests/database/database_initializer.cpp b/libtocc/tests/database/database_initializer.cpp index 84919f8..22c7091 100644 --- a/libtocc/tests/database/database_initializer.cpp +++ b/libtocc/tests/database/database_initializer.cpp @@ -16,15 +16,24 @@ * along with Tocc. If not, see . */ +#include #include +#include "testdb_path.hpp" +#define CATCH_CONFIG_MAIN #include "libtocc/database/database.h" - -// This should be run before all the other database tests, since it's -// initialize an environment for tests. -TEST_CASE("Database Initializer") +std::string testdb_path(const std::string &filename) { - libtocc::Database db("/tmp/tocctests/tocc.test.db"); - db.initialize(); +#ifdef _MSC_VER + return std::string("c:\\temp\\tocctests\\") + std::string(filename); +#else + return std::string("/tmp/tocctests/") + std::string(filename); +#endif } + +/* Database initializer test moved to database_basic_tests.cpp by + * Dick Thiebaud on 2/8/22 because it has to be in the same file + * as other database tests or, under Windows, it is not executed + * before the other tests. +*/ diff --git a/libtocc/tests/database/duplicated_traditional_path_tests.cpp b/libtocc/tests/database/duplicated_traditional_path_tests.cpp index 90646a4..046be47 100644 --- a/libtocc/tests/database/duplicated_traditional_path_tests.cpp +++ b/libtocc/tests/database/duplicated_traditional_path_tests.cpp @@ -16,9 +16,11 @@ * along with Tocc. If not, see . */ +#include "testdb_path.hpp" #include "catch.hpp" #include #include +#include #include "libtocc/common/int_file_info.h" #include "libtocc/common/database_exceptions.h" @@ -28,8 +30,7 @@ TEST_CASE("database: duplicated traditional path tests") { // Creating the database. - libtocc::Database db("/tmp/tocctests/tocc.test.db"); - + libtocc::Database db(testdb_path(DATABASE_FILE).c_str()); // Creating two files without traditional path libtocc::IntFileInfo new_file_1 = db.create_file("Title 1"); libtocc::IntFileInfo new_file_2 = db.create_file("Title 2"); @@ -37,6 +38,7 @@ TEST_CASE("database: duplicated traditional path tests") // Should pass REQUIRE(new_file_1.get_title() == "Title 1"); REQUIRE(new_file_1.get_traditional_path() == ""); + REQUIRE(new_file_2.get_title() == "Title 2"); REQUIRE(new_file_2.get_traditional_path() == ""); diff --git a/libtocc/tests/database/expr_tests.cpp b/libtocc/tests/database/expr_tests.cpp index af6d611..e1a7532 100644 --- a/libtocc/tests/database/expr_tests.cpp +++ b/libtocc/tests/database/expr_tests.cpp @@ -17,6 +17,8 @@ */ #include +#include "testdb_path.hpp" + #include #include "libtocc/exprs/query.h" diff --git a/libtocc/tests/database/find_empty_id_tests.cpp b/libtocc/tests/database/find_empty_id_tests.cpp index 1e7bc9b..d9bd5f0 100644 --- a/libtocc/tests/database/find_empty_id_tests.cpp +++ b/libtocc/tests/database/find_empty_id_tests.cpp @@ -16,6 +16,7 @@ * along with Tocc. If not, see . */ +#include "testdb_path.hpp" #include "catch.hpp" #include #include @@ -28,7 +29,7 @@ TEST_CASE("database: find empty ID") { // Creating the database. - libtocc::Database db("/tmp/tocctests/tocc.test.db"); + libtocc::Database db(testdb_path(DATABASE_FILE).c_str()); // Creating files libtocc::IntFileInfo new_file_1 = db.create_file("file__1", "/old/path/file__1"); diff --git a/libtocc/tests/database/get_file_tests.cpp b/libtocc/tests/database/get_file_tests.cpp index 1c0a051..4218046 100644 --- a/libtocc/tests/database/get_file_tests.cpp +++ b/libtocc/tests/database/get_file_tests.cpp @@ -17,13 +17,15 @@ */ #include +#include "testdb_path.hpp" + #include "libtocc/database/database.h" TEST_CASE("database: get file tests") { // Creating the database. - libtocc::Database db("/tmp/tocctests/tocc.test.db"); + libtocc::Database db(testdb_path(DATABASE_FILE).c_str()); // Getting a not-existed file. REQUIRE_THROWS(db.get("ffr98a0")); diff --git a/libtocc/tests/database/tag_operation_tests.cpp b/libtocc/tests/database/tag_operation_tests.cpp index ab76ef8..0b03006 100644 --- a/libtocc/tests/database/tag_operation_tests.cpp +++ b/libtocc/tests/database/tag_operation_tests.cpp @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with Tocc. If not, see . */ - +#include "testdb_path.hpp" #include #include #include @@ -27,7 +27,7 @@ TEST_CASE("database: tag operation tests") { - libtocc::Database db("/tmp/tocctests/tocc.test.db"); + libtocc::Database db(testdb_path(DATABASE_FILE).c_str()); SECTION("Assigning a single tag") { diff --git a/libtocc/tests/database/wild_card_tests.cpp b/libtocc/tests/database/wild_card_tests.cpp index 03f3c97..7715304 100644 --- a/libtocc/tests/database/wild_card_tests.cpp +++ b/libtocc/tests/database/wild_card_tests.cpp @@ -19,6 +19,7 @@ #include + #include "libtocc/database/funcs.h" diff --git a/libtocc/tests/engine/files_engine_tests.cpp b/libtocc/tests/engine/files_engine_tests.cpp index 31b2392..b74988c 100644 --- a/libtocc/tests/engine/files_engine_tests.cpp +++ b/libtocc/tests/engine/files_engine_tests.cpp @@ -17,7 +17,10 @@ */ #include +#define CATCH_CONFIG_MAIN #include +#include "testdb_path.hpp" + #include "libtocc/common/int_file_info.h" #include "libtocc/database/database.h" @@ -31,8 +34,8 @@ TEST_CASE("engine: files engine tests") /* * Creating instance of files engine. */ - libtocc::Database db("/tmp/tocctests/tocc.test.db"); - libtocc::FileManager file_manager("/tmp/tocctests/"); + libtocc::Database db(testdb_path(DATABASE_FILE).c_str()); + libtocc::FileManager file_manager(testdb_path("").c_str()); libtocc::TagsEngine tags_engine(&db); libtocc::FilesEngine files_engine(&db, &file_manager, &tags_engine); @@ -41,12 +44,12 @@ TEST_CASE("engine: files engine tests") */ // Creating a test file to import. std::ofstream file_stream; - file_stream.open("/tmp/tocctests/tocc_a_file_to_import"); + file_stream.open(testdb_path("tocc_a_file_to_import").c_str()); file_stream << "some data..."; file_stream.close(); // Copying the file. - libtocc::IntFileInfo first_file = files_engine.import_file("/tmp/tocctests/tocc_a_file_to_import"); + libtocc::IntFileInfo first_file = files_engine.import_file(testdb_path("tocc_a_file_to_import").c_str()); // Checking if it's OK. REQUIRE(first_file.get_title() == "tocc_a_file_to_import"); REQUIRE(first_file.get_traditional_path() == ""); diff --git a/libtocc/tests/engine/tags_engine_tests.cpp b/libtocc/tests/engine/tags_engine_tests.cpp index 76bd186..080fba0 100644 --- a/libtocc/tests/engine/tags_engine_tests.cpp +++ b/libtocc/tests/engine/tags_engine_tests.cpp @@ -17,6 +17,8 @@ */ #include +#include "testdb_path.hpp" + #include #include @@ -26,7 +28,7 @@ TEST_CASE("engine: tags engine tests") { // Creating instance of engine. - libtocc::Database db("/tmp/tocctests/tocc.test.db"); + libtocc::Database db(testdb_path(DATABASE_FILE).c_str()); libtocc::TagsEngine tags_engine(&db); // Assigning some tags. diff --git a/libtocc/tests/file_system/file_system_basic_tests.cpp b/libtocc/tests/file_system/file_system_basic_tests.cpp index 1cbfeb1..43c3462 100644 --- a/libtocc/tests/file_system/file_system_basic_tests.cpp +++ b/libtocc/tests/file_system/file_system_basic_tests.cpp @@ -21,18 +21,23 @@ */ #include +#include "testdb_path.hpp" #include #include +#ifdef _MSC_VER +#include "unistdx.h" +#else #include +#endif #include "libtocc/common/base_exception.h" #include "libtocc/file_system/file_manager.h" TEST_CASE("file_system: basic tests") { - std::string base_path = "/tmp/tocctests/"; + std::string base_path = testdb_path(""); std::string file_id = "t00f4ia"; - std::string equivalent_path = "/tmp/tocctests/t/00/fa/ia"; + std::string equivalent_path = testdb_path("t/00/fa/ia"); libtocc::FileManager file_manager(base_path); /* @@ -45,7 +50,9 @@ TEST_CASE("file_system: basic tests") // Creating second file. int file_descriptor_2 = file_manager.create("t00f501"); REQUIRE(file_descriptor_2 > 0); - +#ifdef _MSCCVER +#undef close +#endif close(file_descriptor); close(file_descriptor_2); @@ -72,10 +79,10 @@ TEST_CASE("file_system: basic tests") */ // Creating a test file to copy. std::ofstream file_stream; - file_stream.open("/tmp/tocctests/tocc_test_file_to_copy"); + file_stream.open(testdb_path("tocc_test_file_to_copy").c_str()); file_stream << "some data..."; +#undef close file_stream.close(); - // Coping the file. - file_manager.copy("/tmp/tocctests/tocc_test_file_to_copy", "ta59800"); + file_manager.copy(testdb_path("tocc_test_file_to_copy").c_str(), "ta59800"); } diff --git a/libtocc/tests/front_end/front_end_assign_tag_tests.cpp b/libtocc/tests/front_end/front_end_assign_tag_tests.cpp index af225cc..f679664 100644 --- a/libtocc/tests/front_end/front_end_assign_tag_tests.cpp +++ b/libtocc/tests/front_end/front_end_assign_tag_tests.cpp @@ -18,13 +18,16 @@ #include +#include "testdb_path.hpp" #include "libtocc/front_end/manager.h" +#include "libtocc/common/database_exceptions.h" TEST_CASE("front_end: assign tag") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); manager.assign_tags("0000001", "author:Unknown"); } + diff --git a/libtocc/tests/front_end/front_end_delete_file_tests.cpp b/libtocc/tests/front_end/front_end_delete_file_tests.cpp index b0eec48..d42f5d0 100644 --- a/libtocc/tests/front_end/front_end_delete_file_tests.cpp +++ b/libtocc/tests/front_end/front_end_delete_file_tests.cpp @@ -17,6 +17,8 @@ */ #include +#include "testdb_path.hpp" + #include #include @@ -29,69 +31,69 @@ TEST_CASE("front_end: delete file") { // Creating a file to import. std::ofstream file_stream1; - file_stream1.open("/tmp/tocctests/tocc_test_file_to_delete_1"); + file_stream1.open(testdb_path("tocc_test_file_to_delete_1").c_str()); file_stream1 << "data..."; file_stream1.close(); // Creating a file to import. std::ofstream file_stream2; - file_stream2.open("/tmp/tocctests/tocc_test_file_to_delete_2"); + file_stream2.open(testdb_path("tocc_test_file_to_delete_2").c_str()); file_stream2 << "data..."; file_stream2.close(); //Creating files for collection std::ofstream file_stream3; - file_stream3.open("/tmp/tocctests/tocc_test_file_to_delete_3"); + file_stream3.open(testdb_path("tocc_test_file_to_delete_3").c_str()); file_stream3 << "data..."; file_stream3.close(); std::ofstream file_stream4; - file_stream4.open("/tmp/tocctests/tocc_test_file_to_delete_4"); + file_stream4.open(testdb_path("tocc_test_file_to_delete_4").c_str()); file_stream4 << "data..."; file_stream4.close(); std::ofstream file_stream5; - file_stream5.open("/tmp/tocctests/tocc_test_file_to_delete_5"); + file_stream5.open(testdb_path("tocc_test_file_to_delete_5").c_str()); file_stream5 << "data..."; file_stream5.close(); //Creating files for array's ids std::ofstream file_stream6; - file_stream6.open("/tmp/tocctests/tocc_test_file_to_delete_6"); + file_stream6.open(testdb_path("tocc_test_file_to_delete_6").c_str()); file_stream6 << "data..."; file_stream6.close(); std::ofstream file_stream7; - file_stream7.open("/tmp/tocctests/tocc_test_file_to_delete_7"); + file_stream7.open(testdb_path("tocc_test_file_to_delete_7").c_str()); file_stream7 << "data..."; file_stream7.close(); std::ofstream file_stream8; - file_stream8.open("/tmp/tocctests/tocc_test_file_to_delete_8"); + file_stream8.open(testdb_path("tocc_test_file_to_delete_8").c_str()); file_stream8 << "data..."; file_stream8.close(); // Creating an instance of the manager. - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); // Importing the file libtocc::FileInfo test_file1 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_delete_1"); + manager.import_file(testdb_path("tocc_test_file_to_delete_1").c_str()); libtocc::FileInfo test_file2 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_delete_2"); + manager.import_file(testdb_path("tocc_test_file_to_delete_2").c_str()); std::string file_id = std::string(test_file1.get_id()); //FileInfoCollection libtocc::FileInfo test_file3 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_delete_3"); + manager.import_file(testdb_path("tocc_test_file_to_delete_3").c_str()); libtocc::FileInfo test_file4 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_delete_4"); + manager.import_file(testdb_path("tocc_test_file_to_delete_4").c_str()); libtocc::FileInfo test_file5 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_delete_5"); + manager.import_file(testdb_path("tocc_test_file_to_delete_5").c_str()); libtocc::FileInfo test_file_infos[] = { test_file3, test_file4 }; @@ -99,13 +101,13 @@ TEST_CASE("front_end: delete file") //File ids array libtocc::FileInfo test_file6 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_delete_6"); + manager.import_file(testdb_path("tocc_test_file_to_delete_6").c_str()); libtocc::FileInfo test_file7 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_delete_7"); + manager.import_file(testdb_path("tocc_test_file_to_delete_7").c_str()); libtocc::FileInfo test_file8 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_delete_8"); + manager.import_file(testdb_path("tocc_test_file_to_delete_8").c_str()); std::string file_id6 = std::string(test_file6.get_id()); std::string file_id7 = std::string(test_file7.get_id()); diff --git a/libtocc/tests/front_end/front_end_get_tests.cpp b/libtocc/tests/front_end/front_end_get_tests.cpp index 49ae08b..416731b 100644 --- a/libtocc/tests/front_end/front_end_get_tests.cpp +++ b/libtocc/tests/front_end/front_end_get_tests.cpp @@ -18,6 +18,7 @@ #include +#include "testdb_path.hpp" #include #include @@ -28,7 +29,7 @@ TEST_CASE("front_end: get tests") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); SECTION("file not found error") { @@ -40,19 +41,19 @@ TEST_CASE("front_end: get tests") TEST_CASE("front_end: get_by_traditional_path tests") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); SECTION("existed file") { // Creating a file to import. std::ofstream file_stream; - file_stream.open("/tmp/tocctests/axU87Ryds.txt"); + file_stream.open(testdb_path("axU87Ryds.txt").c_str()); file_stream << "some data..."; file_stream.close(); // Importing the file. libtocc::FileInfo test_file = - manager.import_file("/tmp/tocctests/axU87Ryds.txt", + manager.import_file(testdb_path("axU87Ryds.txt").c_str(), "axU87Ryds.txt", "/old/path/of/test/file/axU87Ryds.txt"); diff --git a/libtocc/tests/front_end/front_end_import_file_tests.cpp b/libtocc/tests/front_end/front_end_import_file_tests.cpp index a340499..197ef0f 100644 --- a/libtocc/tests/front_end/front_end_import_file_tests.cpp +++ b/libtocc/tests/front_end/front_end_import_file_tests.cpp @@ -17,6 +17,8 @@ */ #include +#include "testdb_path.hpp" + #include #include @@ -30,18 +32,18 @@ TEST_CASE("front_end: file import") { // Creating a file to import. std::ofstream file_stream; - file_stream.open("/tmp/tocctests/tocc_test_file_to_import_2"); + file_stream.open(testdb_path("tocc_test_file_to_import_2").c_str()); file_stream << "some data..."; file_stream.close(); // Creating an instance of the manager. - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); SECTION("Importing a file with no property") { // Importing the file with no property. libtocc::FileInfo test_file = - manager.import_file("/tmp/tocctests/tocc_test_file_to_import_2"); + manager.import_file(testdb_path("tocc_test_file_to_import_2").c_str()); // Checking if it's OK. REQUIRE(strcmp(test_file.get_title(), "tocc_test_file_to_import_2") == 0); REQUIRE(strcmp(test_file.get_traditional_path(), "") == 0); @@ -58,7 +60,7 @@ TEST_CASE("front_end: file import") SECTION("Importing the file with Title and Traditional Path") { libtocc::FileInfo test_file_2 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_import_2", + manager.import_file(testdb_path("tocc_test_file_to_import_2").c_str(), "Title of the test file", "/home/not_well_organized/test"); // Checking if it's OK. @@ -80,7 +82,7 @@ TEST_CASE("front_end: file import") tags.add_tag("test"); tags.add_tag("safe-to-remove"); libtocc::FileInfo test_file_3 = - manager.import_file("/tmp/tocctests/tocc_test_file_to_import_2", + manager.import_file(testdb_path("tocc_test_file_to_import_2").c_str(), "Third import", "/home/not_well_organized/test3", &tags); @@ -119,7 +121,7 @@ TEST_CASE("front_end: file import") TEST_CASE("Importing a not-existed file") { // Creating an instance of the manager. - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); REQUIRE_THROWS_AS( manager.import_file("/path/to/a/not/existed/file/fly364bouqc"), diff --git a/libtocc/tests/front_end/front_end_import_utf_file_tests.cpp b/libtocc/tests/front_end/front_end_import_utf_file_tests.cpp index 356631b..120af22 100644 --- a/libtocc/tests/front_end/front_end_import_utf_file_tests.cpp +++ b/libtocc/tests/front_end/front_end_import_utf_file_tests.cpp @@ -17,6 +17,8 @@ */ #include +#include "testdb_path.hpp" + #include #include @@ -29,18 +31,18 @@ TEST_CASE("front_end: UTF file import") { // Creating a file to import. std::ofstream file_stream; - file_stream.open("/tmp/tocctests/测试导入文件"); + file_stream.open(testdb_path("测试导入文件").c_str()); file_stream << "some data..."; file_stream.close(); // Creating an instance of the manager. - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); SECTION("Importing a UTF file with no property") { // Importing the file with no property. libtocc::FileInfo test_file = - manager.import_file("/tmp/tocctests/测试导入文件"); + manager.import_file(testdb_path("测试导入文件").c_str()); // Checking if it's OK. REQUIRE(strcmp(test_file.get_title(), "测试导入文件") == 0); REQUIRE(strcmp(test_file.get_traditional_path(), "") == 0); @@ -57,7 +59,7 @@ TEST_CASE("front_end: UTF file import") SECTION("Importing the UTF file with Title and Traditional Path") { libtocc::FileInfo test_file_2 = - manager.import_file("/tmp/tocctests/测试导入文件", + manager.import_file(testdb_path("测试导入文件").c_str(), "测试", "/home/someone/测试文件"); // Checking if it's OK. @@ -79,7 +81,7 @@ TEST_CASE("front_end: UTF file import") tags.add_tag("اختبار"); tags.add_tag("L'Hôpital"); libtocc::FileInfo test_file_3 = - manager.import_file("/tmp/tocctests/测试导入文件", + manager.import_file(testdb_path("测试导入文件").c_str(), "検査", "/home/L'Hôpital/тестирование", &tags); @@ -118,7 +120,7 @@ TEST_CASE("front_end: UTF file import") TEST_CASE("Importing a not-existed UTF file") { // Creating an instance of the manager. - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); REQUIRE_THROWS_AS( manager.import_file("/مجلد/από/ոչ/存在的/फ़ाइल/fうんこ"), diff --git a/libtocc/tests/front_end/front_end_initializer.cpp b/libtocc/tests/front_end/front_end_initializer.cpp index 7910521..94d6f4b 100644 --- a/libtocc/tests/front_end/front_end_initializer.cpp +++ b/libtocc/tests/front_end/front_end_initializer.cpp @@ -17,6 +17,9 @@ */ #include +#include "testdb_path.hpp" +#include + #include "libtocc/front_end/manager.h" @@ -25,6 +28,7 @@ // environment for them. TEST_CASE("Front End Initializer") { - libtocc::Manager manager("/tmp/tocctests/"); + std::string path = testdb_path("frontend").c_str(); + libtocc::Manager manager(path.c_str()); manager.initialize(); } diff --git a/libtocc/tests/front_end/front_end_set_file_title.cpp b/libtocc/tests/front_end/front_end_set_file_title.cpp index 2110c79..0b31f1b 100644 --- a/libtocc/tests/front_end/front_end_set_file_title.cpp +++ b/libtocc/tests/front_end/front_end_set_file_title.cpp @@ -17,6 +17,8 @@ */ #include +#include "testdb_path.hpp" + #include #include @@ -32,22 +34,22 @@ TEST_CASE("front_end: set files title tests") //Creating files std::ofstream file_stream1; - file_stream1.open("/tmp/tocctests/tocc_test_random_file_1"); + file_stream1.open(testdb_path("tocc_test_random_file_1").c_str()); file_stream1 << "I'm file 1"; file_stream1.close(); // Creating a file to import. std::ofstream file_stream2; - file_stream1.open("/tmp/tocctests/tocc_test_random_file_2"); + file_stream1.open(testdb_path("tocc_test_random_file_2").c_str()); file_stream1 << "I'm file 2"; file_stream1.close(); // Creating an instance of the manager. - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); // Creating 2 files with a title and a traditional path. - libtocc::FileInfo new_file1 = manager.import_file("/tmp/tocctests/tocc_test_random_file_1"); - libtocc::FileInfo new_file2 = manager.import_file("/tmp/tocctests/tocc_test_random_file_2"); + libtocc::FileInfo new_file1 = manager.import_file(testdb_path("tocc_test_random_file_1").c_str()); + libtocc::FileInfo new_file2 = manager.import_file(testdb_path("tocc_test_random_file_2").c_str()); //Setting the title of the first file manager.set_title(new_file1.get_id(), "new title 1"); diff --git a/libtocc/tests/front_end/front_end_tag_statistics_tests.cpp b/libtocc/tests/front_end/front_end_tag_statistics_tests.cpp index 220baf2..7bd8418 100644 --- a/libtocc/tests/front_end/front_end_tag_statistics_tests.cpp +++ b/libtocc/tests/front_end/front_end_tag_statistics_tests.cpp @@ -18,6 +18,8 @@ #include +#include "testdb_path.hpp" + #include #include @@ -28,20 +30,20 @@ TEST_CASE("Tag Statistics: All Tags") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); SECTION("Single File") { /* * Preparing test data. */ - const char* file_path = "/tmp/tocctests/tocc_statistics_test_file.tmp"; + std::string file_path = testdb_path("tocc_statistics_test_file.tmp"); std::ofstream file_to_import(file_path); file_to_import << "some data..."; file_to_import.close(); - libtocc::FileInfo test_file = manager.import_file(file_path); + libtocc::FileInfo test_file = manager.import_file(file_path.c_str()); libtocc::TagsCollection tags; tags.add_tag("tag_statistics_test_01"); @@ -75,8 +77,8 @@ TEST_CASE("Tag Statistics: All Tags") /* * Creating test file. */ - const char* file_path = "/tmp/tocctests/tocc_statistics_test_file_ufHf89.tmp"; - std::ofstream file_to_import(file_path); + std::string file_path = testdb_path("tocc_statistics_test_file_ufHf89.tmp"); + std::ofstream file_to_import(file_path.c_str()); file_to_import << "some data..."; file_to_import.close(); @@ -93,18 +95,18 @@ TEST_CASE("Tag Statistics: All Tags") * Importing and assigning tags. */ libtocc::FileInfo test_file_01 = - manager.import_file(file_path); + manager.import_file(file_path.c_str()); manager.assign_tags(test_file_01.get_id(), &tags_1); libtocc::FileInfo test_file_02 = - manager.import_file(file_path); + manager.import_file(file_path.c_str()); manager.assign_tags(test_file_02.get_id(), &tags_1); manager.assign_tags(test_file_02.get_id(), &tags_2); libtocc::FileInfo test_file_03 = - manager.import_file(file_path); + manager.import_file(file_path.c_str()); manager.assign_tags(test_file_03.get_id(), &tags_1); @@ -135,13 +137,13 @@ TEST_CASE("Tag Statistics: All Tags") TEST_CASE("Tag Statistics: Tags of Files") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); /* * Creating test file. */ - const char* file_path = "/tmp/tocctests/tocc_statistics_test_file_yu78NBq.tmp"; - std::ofstream file_to_import(file_path); + std::string file_path = testdb_path("tocc_statistics_test_file_yu78NBq.tmp").c_str(); + std::ofstream file_to_import(file_path.c_str()); file_to_import << "some data..."; file_to_import.close(); @@ -158,12 +160,12 @@ TEST_CASE("Tag Statistics: Tags of Files") * Importing and assigning tags. */ libtocc::FileInfo test_file_01 = - manager.import_file(file_path); + manager.import_file(file_path.c_str()); manager.assign_tags(test_file_01.get_id(), &tags_1); libtocc::FileInfo test_file_02 = - manager.import_file(file_path); + manager.import_file(file_path.c_str()); manager.assign_tags(test_file_02.get_id(), &tags_1); manager.assign_tags(test_file_02.get_id(), &tags_2); diff --git a/libtocc/tests/front_end/query_files_tests.cpp b/libtocc/tests/front_end/query_files_tests.cpp index 3e9361d..0bc500b 100644 --- a/libtocc/tests/front_end/query_files_tests.cpp +++ b/libtocc/tests/front_end/query_files_tests.cpp @@ -17,6 +17,8 @@ */ #include +#include "testdb_path.hpp" + #include #include @@ -30,7 +32,7 @@ TEST_CASE("query_files_tests: simple tag search") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); SECTION("Assign and search 'test_tag_0xUi7'") { @@ -92,16 +94,17 @@ TEST_CASE("query_files_tests: simple tag search") TEST_CASE("query_files_tests: simple title search") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); SECTION("Import and query `IMG007'") { std::ofstream file_stream; - file_stream.open("/tmp/tocctests/XlfYru129384PxQ"); + file_stream.open(testdb_path("XlfYru129384PxQ").c_str()); file_stream << "Not a real photo!"; file_stream.close(); - libtocc::FileInfo original_file = manager.import_file("/tmp/tocctests/XlfYru129384PxQ", "IMG007"); + libtocc::FileInfo original_file = manager.import_file(testdb_path("XlfYru129384PxQ").c_str(), + "IMG007"); libtocc::Title title_expr("IMG007"); libtocc::And main_and(title_expr); @@ -123,9 +126,9 @@ TEST_CASE("query_files_tests: simple title search") TEST_CASE("query_files_tests: long query test") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); - std::string test_file = "/tmp/tocctests/iU83FpdAdjcAppfkdj"; + std::string test_file = testdb_path("iU83FpdAdjcAppfkdj"); std::ofstream file_stream; file_stream.open(test_file.c_str()); @@ -169,11 +172,11 @@ TEST_CASE("query_files_tests: long query test") TEST_CASE("query_files_tests: Not Equal tests") { - libtocc::Manager manager("/tmp/tocctests/"); + libtocc::Manager manager(testdb_path("").c_str()); // Creating two test files. - std::string test_file_1 = "/tmp/tocctests/libtocctests_Unx12Pfiedkc"; - std::string test_file_2 = "/tmp/tocctests/libtocctests_fPe98ncloEqs"; + std::string test_file_1 = testdb_path("libtocctests_Unx12Pfiedkc"); + std::string test_file_2 = testdb_path("libtocctests_fPe98ncloEqs"); std::ofstream file_stream; file_stream.open(test_file_1.c_str()); diff --git a/libtocc/tests/main.cpp b/libtocc/tests/main.cpp index 17db850..f2ceeaa 100644 --- a/libtocc/tests/main.cpp +++ b/libtocc/tests/main.cpp @@ -22,6 +22,7 @@ // The following define causes the Catch to generate a main fucntion here. #define CATCH_CONFIG_MAIN +#include "testdb_path.hpp" #include "catch.hpp" #include @@ -35,19 +36,26 @@ class TestInitialiser TestInitialiser() { // clean previous test files - if (int status = system("rm -rf /tmp/tocctests")) + +#ifdef _MSC_VER + std::string cmd_string = std::string("cmd.exe /c rmdir /s /q ") + testdb_path(""); +#else + std::string cmd_string = std::string("rm -rf ") + testdb_path(""); +#endif + if (int status = system(cmd_string.c_str())) { std::cout << "Test initialisation failed -\ Unable to delete files" << std::endl; exit(status); } - else if (int status = system("mkdir /tmp/tocctests")) + std::string mkdir_cmd = (std::string("mkdir ") + testdb_path("")).c_str(); + if (int status = system(mkdir_cmd.c_str())) { std::cout << "Test initialisation failed -\ - Unable to create base directory" << std::endl; + Unable to create base directory" << std::endl; exit(status); } - }; + }; }; TestInitialiser now; diff --git a/libtocc/tests/testdb_path.hpp b/libtocc/tests/testdb_path.hpp new file mode 100644 index 0000000..c7d7dd7 --- /dev/null +++ b/libtocc/tests/testdb_path.hpp @@ -0,0 +1,6 @@ +#pragma once +#include +std::string testdb_path(const std::string &filename); +#ifdef _MSC_VER +#pragma warning(disable:4521) +#endif diff --git a/msvc/catch2/catch2/catch2.vcxproj b/msvc/catch2/catch2/catch2.vcxproj new file mode 100644 index 0000000..e458aea --- /dev/null +++ b/msvc/catch2/catch2/catch2.vcxproj @@ -0,0 +1,137 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {A9891DAC-1D48-4185-B38B-0719FBAEB787} + catch2 + 10.0.17763.0 + catch_amalgamated + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + StaticLibrary + true + v143 + MultiByte + + + StaticLibrary + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + MultiThreadedDebug + + + Console + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + MultiThreadedDLL + + + Console + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/catch2/catch2/catch2.vcxproj.filters b/msvc/catch2/catch2/catch2.vcxproj.filters new file mode 100644 index 0000000..1496eb6 --- /dev/null +++ b/msvc/catch2/catch2/catch2.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/msvc/catch2/catch2/catch2.vcxproj.user b/msvc/catch2/catch2/catch2.vcxproj.user new file mode 100644 index 0000000..6e2aec7 --- /dev/null +++ b/msvc/catch2/catch2/catch2.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/msvc/cli/cli/cli.vcxproj b/msvc/cli/cli/cli.vcxproj new file mode 100644 index 0000000..40cb399 --- /dev/null +++ b/msvc/cli/cli/cli.vcxproj @@ -0,0 +1,182 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {48261702-8FB4-4D7D-BD79-97DABE1293AA} + cli + 10.0.17763.0 + tocc + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + false + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + ..\..\x64\Debug;$(LibraryPath) + + + ..\..\x64\Release;$(LibraryPath) + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + Disabled + true + true + ..\..\..\cli\src;..\..\..\libtocc\src\;%(AdditionalIncludeDirectories) + MultiThreadedDebug + true + + + Console + unqlite.lib;libtocc.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + ..\..\..\cli\src;..\..\..\libtocc\src\;%(AdditionalIncludeDirectories) + MultiThreadedDLL + + + Console + true + true + libtocc.lib;unqlite.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/cli/cli/cli.vcxproj.filters b/msvc/cli/cli/cli.vcxproj.filters new file mode 100644 index 0000000..9bb76c6 --- /dev/null +++ b/msvc/cli/cli/cli.vcxproj.filters @@ -0,0 +1,129 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/msvc/cli/cli/cli.vcxproj.user b/msvc/cli/cli/cli.vcxproj.user new file mode 100644 index 0000000..6e2aec7 --- /dev/null +++ b/msvc/cli/cli/cli.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/msvc/cli/tocc-initialize/tocc-initialize.vcxproj b/msvc/cli/tocc-initialize/tocc-initialize.vcxproj new file mode 100644 index 0000000..07b05d6 --- /dev/null +++ b/msvc/cli/tocc-initialize/tocc-initialize.vcxproj @@ -0,0 +1,142 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {BA530774-6D09-44CF-9022-5F10E870C5BF} + toccinitialize + 10.0.17763.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + ..\..\x64\Debug;$(LibraryPath) + + + ..\..\x64\Release;$(LibraryPath) + + + + Level3 + Disabled + true + true + ..\..\..\libtocc\src;%(AdditionalIncludeDirectories) + MultiThreadedDebug + + + Console + libtocc.lib;unqlite.lib;%(AdditionalDependencies) + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + ..\..\..\libtocc\src;%(AdditionalIncludeDirectories) + + + Console + true + true + unqlite.lib;libtocc.lib;%(AdditionalDependencies) + + + + + + + + + + \ No newline at end of file diff --git a/msvc/cli/tocc-initialize/tocc-initialize.vcxproj.filters b/msvc/cli/tocc-initialize/tocc-initialize.vcxproj.filters new file mode 100644 index 0000000..df4fda1 --- /dev/null +++ b/msvc/cli/tocc-initialize/tocc-initialize.vcxproj.filters @@ -0,0 +1,25 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/msvc/cli/tocc-initialize/tocc-initialize.vcxproj.user b/msvc/cli/tocc-initialize/tocc-initialize.vcxproj.user new file mode 100644 index 0000000..6e2aec7 --- /dev/null +++ b/msvc/cli/tocc-initialize/tocc-initialize.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/msvc/libtocc/libtocc.sln b/msvc/libtocc/libtocc.sln new file mode 100644 index 0000000..104e85b --- /dev/null +++ b/msvc/libtocc/libtocc.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32112.339 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtocc", "libtocc.vcxproj", "{D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Debug|x64.ActiveCfg = Debug|x64 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Debug|x64.Build.0 = Debug|x64 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Debug|x86.ActiveCfg = Debug|Win32 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Debug|x86.Build.0 = Debug|Win32 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Release|x64.ActiveCfg = Release|x64 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Release|x64.Build.0 = Release|x64 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Release|x86.ActiveCfg = Release|Win32 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {623B689B-7E96-40AD-89EC-8524FB109271} + EndGlobalSection +EndGlobal diff --git a/msvc/libtocc/libtocc.vcxproj b/msvc/libtocc/libtocc.vcxproj new file mode 100644 index 0000000..6f3bd62 --- /dev/null +++ b/msvc/libtocc/libtocc.vcxproj @@ -0,0 +1,183 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72} + Win32Proj + 10.0.17763.0 + + + + StaticLibrary + true + v143 + + + Application + false + v143 + + + StaticLibrary + true + v143 + + + StaticLibrary + false + v143 + + + + + + + + + + + + + + + + + + + + + true + C:\src\tocc\msvc\Debug;$(LibraryPath) + + + true + + + $(IncludePath) + + + + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDebug + Level3 + ProgramDatabase + Disabled + C:\src\tocc\Catch2-devel\extras;C:\src\unq;C:\src\tocc\libtocc\src;%(AdditionalIncludeDirectories) + true + + + MachineX86 + true + Windows + C:\src\tocc\msvc\x64\Debug;%(AdditionalLibraryDirectories) + unqlite.lib;%(AdditionalDependencies) + + + + + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDLL + Level3 + ProgramDatabase + + + MachineX86 + true + Windows + true + true + + + + + ..\..\unqlite;..\..\libtocc\src;%(AdditionalIncludeDirectories) + MultiThreadedDebug + + + + + ..\..\unqlite;..\..\libtocc\src;%(AdditionalIncludeDirectories) + MultiThreadedDLL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/libtocc/libtocc.vcxproj.filters b/msvc/libtocc/libtocc.vcxproj.filters new file mode 100644 index 0000000..b7e15fd --- /dev/null +++ b/msvc/libtocc/libtocc.vcxproj.filters @@ -0,0 +1,186 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/msvc/libtocc/libtocc.vcxproj.user b/msvc/libtocc/libtocc.vcxproj.user new file mode 100644 index 0000000..0f14913 --- /dev/null +++ b/msvc/libtocc/libtocc.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/msvc/libtocctests.sln b/msvc/libtocctests.sln new file mode 100644 index 0000000..984f1fb --- /dev/null +++ b/msvc/libtocctests.sln @@ -0,0 +1,97 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32210.238 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtocctests", "libtocctests.vcxproj", "{AC44CED4-34EE-4D63-9CFC-92A59F0797AA}" + ProjectSection(ProjectDependencies) = postProject + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72} = {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72} + {CDC87491-CA98-4097-B320-FA7FA4CA6D77} = {CDC87491-CA98-4097-B320-FA7FA4CA6D77} + {A9891DAC-1D48-4185-B38B-0719FBAEB787} = {A9891DAC-1D48-4185-B38B-0719FBAEB787} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtocc", "libtocc\libtocc.vcxproj", "{D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}" + ProjectSection(ProjectDependencies) = postProject + {CDC87491-CA98-4097-B320-FA7FA4CA6D77} = {CDC87491-CA98-4097-B320-FA7FA4CA6D77} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unqlite", "unqlite\unqlite.vcxproj", "{CDC87491-CA98-4097-B320-FA7FA4CA6D77}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "catch_amalgamated", "catch2\catch2\catch2.vcxproj", "{A9891DAC-1D48-4185-B38B-0719FBAEB787}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tocc", "cli\cli\cli.vcxproj", "{48261702-8FB4-4D7D-BD79-97DABE1293AA}" + ProjectSection(ProjectDependencies) = postProject + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72} = {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72} + {CDC87491-CA98-4097-B320-FA7FA4CA6D77} = {CDC87491-CA98-4097-B320-FA7FA4CA6D77} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tocc-initialize", "cli\tocc-initialize\tocc-initialize.vcxproj", "{BA530774-6D09-44CF-9022-5F10E870C5BF}" + ProjectSection(ProjectDependencies) = postProject + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72} = {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72} + {CDC87491-CA98-4097-B320-FA7FA4CA6D77} = {CDC87491-CA98-4097-B320-FA7FA4CA6D77} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA}.Debug|x64.ActiveCfg = Debug|x64 + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA}.Debug|x64.Build.0 = Debug|x64 + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA}.Debug|x86.ActiveCfg = Debug|Win32 + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA}.Debug|x86.Build.0 = Debug|Win32 + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA}.Release|x64.ActiveCfg = Release|x64 + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA}.Release|x64.Build.0 = Release|x64 + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA}.Release|x86.ActiveCfg = Release|Win32 + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA}.Release|x86.Build.0 = Release|Win32 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Debug|x64.ActiveCfg = Debug|x64 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Debug|x64.Build.0 = Debug|x64 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Debug|x86.ActiveCfg = Debug|Win32 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Debug|x86.Build.0 = Debug|Win32 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Release|x64.ActiveCfg = Release|x64 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Release|x64.Build.0 = Release|x64 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Release|x86.ActiveCfg = Release|Win32 + {D2D62C07-48E2-4B7C-AAE2-A0B0519CDA72}.Release|x86.Build.0 = Release|Win32 + {CDC87491-CA98-4097-B320-FA7FA4CA6D77}.Debug|x64.ActiveCfg = Debug|x64 + {CDC87491-CA98-4097-B320-FA7FA4CA6D77}.Debug|x64.Build.0 = Debug|x64 + {CDC87491-CA98-4097-B320-FA7FA4CA6D77}.Debug|x86.ActiveCfg = Debug|Win32 + {CDC87491-CA98-4097-B320-FA7FA4CA6D77}.Debug|x86.Build.0 = Debug|Win32 + {CDC87491-CA98-4097-B320-FA7FA4CA6D77}.Release|x64.ActiveCfg = Release|x64 + {CDC87491-CA98-4097-B320-FA7FA4CA6D77}.Release|x64.Build.0 = Release|x64 + {CDC87491-CA98-4097-B320-FA7FA4CA6D77}.Release|x86.ActiveCfg = Release|Win32 + {CDC87491-CA98-4097-B320-FA7FA4CA6D77}.Release|x86.Build.0 = Release|Win32 + {A9891DAC-1D48-4185-B38B-0719FBAEB787}.Debug|x64.ActiveCfg = Debug|x64 + {A9891DAC-1D48-4185-B38B-0719FBAEB787}.Debug|x64.Build.0 = Debug|x64 + {A9891DAC-1D48-4185-B38B-0719FBAEB787}.Debug|x86.ActiveCfg = Debug|Win32 + {A9891DAC-1D48-4185-B38B-0719FBAEB787}.Debug|x86.Build.0 = Debug|Win32 + {A9891DAC-1D48-4185-B38B-0719FBAEB787}.Release|x64.ActiveCfg = Release|x64 + {A9891DAC-1D48-4185-B38B-0719FBAEB787}.Release|x64.Build.0 = Release|x64 + {A9891DAC-1D48-4185-B38B-0719FBAEB787}.Release|x86.ActiveCfg = Release|Win32 + {A9891DAC-1D48-4185-B38B-0719FBAEB787}.Release|x86.Build.0 = Release|Win32 + {48261702-8FB4-4D7D-BD79-97DABE1293AA}.Debug|x64.ActiveCfg = Debug|x64 + {48261702-8FB4-4D7D-BD79-97DABE1293AA}.Debug|x64.Build.0 = Debug|x64 + {48261702-8FB4-4D7D-BD79-97DABE1293AA}.Debug|x86.ActiveCfg = Debug|Win32 + {48261702-8FB4-4D7D-BD79-97DABE1293AA}.Debug|x86.Build.0 = Debug|Win32 + {48261702-8FB4-4D7D-BD79-97DABE1293AA}.Release|x64.ActiveCfg = Release|x64 + {48261702-8FB4-4D7D-BD79-97DABE1293AA}.Release|x64.Build.0 = Release|x64 + {48261702-8FB4-4D7D-BD79-97DABE1293AA}.Release|x86.ActiveCfg = Release|Win32 + {48261702-8FB4-4D7D-BD79-97DABE1293AA}.Release|x86.Build.0 = Release|Win32 + {BA530774-6D09-44CF-9022-5F10E870C5BF}.Debug|x64.ActiveCfg = Debug|x64 + {BA530774-6D09-44CF-9022-5F10E870C5BF}.Debug|x64.Build.0 = Debug|x64 + {BA530774-6D09-44CF-9022-5F10E870C5BF}.Debug|x86.ActiveCfg = Debug|Win32 + {BA530774-6D09-44CF-9022-5F10E870C5BF}.Debug|x86.Build.0 = Debug|Win32 + {BA530774-6D09-44CF-9022-5F10E870C5BF}.Release|x64.ActiveCfg = Release|x64 + {BA530774-6D09-44CF-9022-5F10E870C5BF}.Release|x64.Build.0 = Release|x64 + {BA530774-6D09-44CF-9022-5F10E870C5BF}.Release|x86.ActiveCfg = Release|Win32 + {BA530774-6D09-44CF-9022-5F10E870C5BF}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B8186089-BE05-402A-9D8A-2960E715B5A7} + EndGlobalSection +EndGlobal diff --git a/msvc/libtocctests.vcxproj b/msvc/libtocctests.vcxproj new file mode 100644 index 0000000..5ae3667 --- /dev/null +++ b/msvc/libtocctests.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {AC44CED4-34EE-4D63-9CFC-92A59F0797AA} + Win32Proj + 10.0.17763.0 + + + + Application + true + v143 + false + + + Application + false + v143 + + + Application + true + v143 + + + Application + false + v143 + + + + + + + + + + + + + + + + + + + + + true + C:\src\tocc\msvc\Debug;$(LibraryPath) + + + true + + + $(IncludePath) + .\x64\Debug;$(LibraryPath) + true + + + unqlite\x64\Release;x64\Release;$(LibraryPath) + + + + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDebug + Level3 + ProgramDatabase + Disabled + C:\src\tocc\Catch2-devel\extras;C:\src\unq;C:\src\tocc\libtocc\tests;C:\src\tocc\libtocc\src;%(AdditionalIncludeDirectories) + false + true + CompileAsCpp + AnySuitable + + + MachineX86 + true + Console + libtocc.lib;unqlite.lib;%(AdditionalDependencies) + false + + + + + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + Level3 + ProgramDatabase + + + MachineX86 + true + Console + true + true + + + + + ..\libtocc\tests;..\unqlite;..\libtocc\src;%(AdditionalIncludeDirectories) + MultiThreadedDebug + + + Console + unqlite.lib;catch_amalgamated.lib;libtocc.lib;%(AdditionalDependencies) + + + + + ..\unqlite;..\libtocc\tests;..\libtocc\src;%(AdditionalIncludeDirectories) + MultiThreadedDLL + + + unqlite.lib;libtocc.lib;catch_amalgamated.lib;%(AdditionalDependencies) + UseLinkTimeCodeGeneration + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/libtocctests.vcxproj.user b/msvc/libtocctests.vcxproj.user new file mode 100644 index 0000000..6e2aec7 --- /dev/null +++ b/msvc/libtocctests.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/msvc/toccfs/toccfs.vcxproj b/msvc/toccfs/toccfs.vcxproj new file mode 100644 index 0000000..ffe9bce --- /dev/null +++ b/msvc/toccfs/toccfs.vcxproj @@ -0,0 +1,144 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {18C96336-B29B-444F-A7A2-95F381E7203C} + toccfs + 10.0.17763.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + C:\Program Files %28x86%29\WinFsp\inc\fuse;..\..\libtocc\src;..\..\toccfs\src;$(VC_IncludePath);$(WindowsSDK_IncludePath) + + + + Level3 + Disabled + true + true + C:\Program Files %28x86%29\WinFsp\inc\fuse;%(AdditionalIncludeDirectories) + + + Console + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + G:\tocc\toccfs\src;..\..\libtocc\src;..\..\toccfs\src;%(AdditionalIncludeDirectories) + + + Console + true + true + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/toccfs/toccfs.vcxproj.filters b/msvc/toccfs/toccfs.vcxproj.filters new file mode 100644 index 0000000..ff2d289 --- /dev/null +++ b/msvc/toccfs/toccfs.vcxproj.filters @@ -0,0 +1,45 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/msvc/toccfs/toccfs.vcxproj.user b/msvc/toccfs/toccfs.vcxproj.user new file mode 100644 index 0000000..6e2aec7 --- /dev/null +++ b/msvc/toccfs/toccfs.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/msvc/unqlite/unqlite.vcxproj b/msvc/unqlite/unqlite.vcxproj new file mode 100644 index 0000000..822d8b8 --- /dev/null +++ b/msvc/unqlite/unqlite.vcxproj @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {cdc87491-ca98-4097-b320-fa7fa4ca6d77} + unqlite + 10.0.17763.0 + + + + StaticLibrary + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + .lib + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreadedDLL + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/unqlite/unqlite.vcxproj.filters b/msvc/unqlite/unqlite.vcxproj.filters new file mode 100644 index 0000000..a360371 --- /dev/null +++ b/msvc/unqlite/unqlite.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/msvc/unqlite/unqlite.vcxproj.user b/msvc/unqlite/unqlite.vcxproj.user new file mode 100644 index 0000000..0f14913 --- /dev/null +++ b/msvc/unqlite/unqlite.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/toccfs/docs/source/compile.rst b/toccfs/docs/source/compile.rst index 94d25f0..1c187c6 100644 --- a/toccfs/docs/source/compile.rst +++ b/toccfs/docs/source/compile.rst @@ -6,6 +6,9 @@ Compiling Toccfs from Source ============================ +Note: *toccfs* in only supported for Unix-like OS's (Linux, BSD, etc). It +is not supported for Microsoft Windows. + Requirements ------------ *toccfs* wrote using FUSE (File System in User Environment) library. So, you