diff --git a/cvmfs/CMakeLists.txt b/cvmfs/CMakeLists.txt index 6fcacfbbfeee0d69cc471eff46a6ac65815ed82c..b6c24e90fea08893eb9b3993057445a3b302973a 100644 --- a/cvmfs/CMakeLists.txt +++ b/cvmfs/CMakeLists.txt @@ -334,6 +334,7 @@ set (LIBCVMFS_SERVER_SOURCES sanitizer.cc session_context.cc signature.cc + shortstring.cc sql.cc sqlitemem.cc ssl.cc @@ -423,6 +424,7 @@ set (CVMFS_SWISSKNIFE_SOURCES session_context.cc signature.cc signing_tool.cc + shortstring.cc sql.cc sqlitemem.cc ssl.cc @@ -620,6 +622,7 @@ if(BUILD_RECEIVER) session_context.cc signature.cc signing_tool.cc + shortstring.cc ssl.cc statistics.cc statistics_database.cc diff --git a/cvmfs/shortstring.cc b/cvmfs/shortstring.cc new file mode 100644 index 0000000000000000000000000000000000000000..edb19697041cd4dcc6bc035655787d39dbcba742 --- /dev/null +++ b/cvmfs/shortstring.cc @@ -0,0 +1,49 @@ +/** + * This file is part of the CernVM File System. + * + * Some common functions. + */ + + +#include "cvmfs_config.h" +#include "shortstring.h" + +#ifdef CVMFS_NAMESPACE_GUARD +namespace CVMFS_NAMESPACE_GUARD { +#endif + +PathString GetParentPath(const PathString &path) { + int length = static_cast<int>(path.GetLength()); + if (length == 0) + return path; + const char *chars = path.GetChars(); + + for (int i = length-1; i >= 0; --i) { + if (chars[i] == '/') + return PathString(chars, i); + } + + return path; +} + +NameString GetFileName(const PathString &path) { + NameString name; + int length = static_cast<int>(path.GetLength()); + const char *chars = path.GetChars(); + + int i; + for (i = length-1; i >= 0; --i) { + if (chars[i] == '/') + break; + } + i++; + if (i < length) { + name.Append(chars+i, length-i); + } + + return name; +} + +#ifdef CVMFS_NAMESPACE_GUARD +} // namespace CVMFS_NAMESPACE_GUARD +#endif diff --git a/cvmfs/shortstring.h b/cvmfs/shortstring.h index 968733d629d2b721ae256e61145167f7a23508ff..9371b206ac45088b0f579b27e62443d66317f610 100644 --- a/cvmfs/shortstring.h +++ b/cvmfs/shortstring.h @@ -196,6 +196,11 @@ atomic_int64 ShortString<StackSize, Type>::num_overflows_ = 0; template<unsigned char StackSize, char Type> atomic_int64 ShortString<StackSize, Type>::num_instances_ = 0; +// See posix.cc for the std::string counterparts +PathString GetParentPath(const PathString &path); +NameString GetFileName(const PathString &path); + + #ifdef CVMFS_NAMESPACE_GUARD } // namespace CVMFS_NAMESPACE_GUARD #endif diff --git a/cvmfs/shrinkwrap/posix/garbage_collector.cc b/cvmfs/shrinkwrap/posix/garbage_collector.cc index 9e46972d6377f609ee56c6dcbb9553ac3d6ee597..6bb4cb62459c2ff2d1a408b11c605f9775ecb8f0 100644 --- a/cvmfs/shrinkwrap/posix/garbage_collector.cc +++ b/cvmfs/shrinkwrap/posix/garbage_collector.cc @@ -5,7 +5,9 @@ #include <dirent.h> #include <errno.h> -#include <stdio.h> + +#include <cstdio> +#include <cstring> #include <map> #include <string> diff --git a/cvmfs/util/namespace.cc b/cvmfs/util/namespace.cc index f241fd4b09b6839bf9281132c2eb24b931361440..f8349849d4a032cb17228d33edd3f3268982309d 100644 --- a/cvmfs/util/namespace.cc +++ b/cvmfs/util/namespace.cc @@ -13,6 +13,8 @@ #endif #include <sys/wait.h> +#include <cstring> + #include "util/posix.h" #include "util/string.h" diff --git a/cvmfs/util/posix.cc b/cvmfs/util/posix.cc index abb534a54aa45ae01a360bce11e78fc2425a5f4a..547c60b03f0a1fdc882d32458369aedc408e811b 100644 --- a/cvmfs/util/posix.cc +++ b/cvmfs/util/posix.cc @@ -137,24 +137,6 @@ std::string GetParentPath(const std::string &path) { } -/** - * Gets the file name part of a path. - */ -PathString GetParentPath(const PathString &path) { - int length = static_cast<int>(path.GetLength()); - if (length == 0) - return path; - const char *chars = path.GetChars(); - - for (int i = length-1; i >= 0; --i) { - if (chars[i] == '/') - return PathString(chars, i); - } - - return path; -} - - /** * Gets the file name part of a path. */ @@ -168,25 +150,6 @@ std::string GetFileName(const std::string &path) { } -NameString GetFileName(const PathString &path) { - NameString name; - int length = static_cast<int>(path.GetLength()); - const char *chars = path.GetChars(); - - int i; - for (i = length-1; i >= 0; --i) { - if (chars[i] == '/') - break; - } - i++; - if (i < length) { - name.Append(chars+i, length-i); - } - - return name; -} - - bool IsAbsolutePath(const std::string &path) { return (!path.empty() && path[0] == '/'); } diff --git a/cvmfs/util/posix.h b/cvmfs/util/posix.h index d07fbac199d33a3dfea478b25b4991818a6af6ef..8eaee3fbd5764c37af96d10d97c083b58b30b3e4 100644 --- a/cvmfs/util/posix.h +++ b/cvmfs/util/posix.h @@ -19,7 +19,6 @@ #include <string> #include <vector> -#include "shortstring.h" #include "util/pointer.h" #include "util/single_copy.h" @@ -65,9 +64,7 @@ struct LsofEntry { std::string MakeCanonicalPath(const std::string &path); std::string GetParentPath(const std::string &path); -PathString GetParentPath(const PathString &path); std::string GetFileName(const std::string &path); -NameString GetFileName(const PathString &path); void SplitPath(const std::string &path, std::string *dirname, std::string *filename); diff --git a/test/stress/CMakeLists.txt b/test/stress/CMakeLists.txt index d0d6dd2545cefaf20a922b51cae6d540a2ba8ce6..d062300f4b153d02be3bdd78ee798941bce035d6 100644 --- a/test/stress/CMakeLists.txt +++ b/test/stress/CMakeLists.txt @@ -6,7 +6,6 @@ set (CVMFS_STRESS_SOURCES ${CVMFS_SOURCE_DIR}/gateway_util.cc ${CVMFS_SOURCE_DIR}/hash.cc ${CVMFS_SOURCE_DIR}/json_document.cc - ${CVMFS_SOURCE_DIR}/logging.cc ${CVMFS_SOURCE_DIR}/options.cc ${CVMFS_SOURCE_DIR}/pack.cc ${CVMFS_SOURCE_DIR}/s3fanout.cc @@ -22,6 +21,7 @@ set (CVMFS_STRESS_SOURCES ${CVMFS_SOURCE_DIR}/upload_spooler_definition.cc ${CVMFS_SOURCE_DIR}/util/exception.cc ${CVMFS_SOURCE_DIR}/util/file_backed_buffer.cc + ${CVMFS_SOURCE_DIR}/util/logging.cc ${CVMFS_SOURCE_DIR}/util/mmap_file.cc ${CVMFS_SOURCE_DIR}/util/posix.cc ${CVMFS_SOURCE_DIR}/util/string.cc diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index e2423244750ec8f7ab1e9e26e5b8beb14f2929de..d7f0b2b08f7d667a47fa76d830cf18a0f7fd76b7 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -230,6 +230,7 @@ set (CVMFS_UNITTEST_SOURCES ${CVMFS_SOURCE_DIR}/session_context.cc ${CVMFS_SOURCE_DIR}/signature.cc ${CVMFS_SOURCE_DIR}/signing_tool.cc + ${CVMFS_SOURCE_DIR}/shortstring.cc ${CVMFS_SOURCE_DIR}/sql.cc ${CVMFS_SOURCE_DIR}/sqlitemem.cc ${CVMFS_SOURCE_DIR}/sqlitevfs.cc @@ -503,6 +504,7 @@ set (CVMFS_TEST_PUBLISH_SOURCES ${CVMFS_SOURCE_DIR}/sanitizer.cc ${CVMFS_SOURCE_DIR}/session_context.cc ${CVMFS_SOURCE_DIR}/signature.cc + ${CVMFS_SOURCE_DIR}/shortstring.cc ${CVMFS_SOURCE_DIR}/sql.cc ${CVMFS_SOURCE_DIR}/sqlitemem.cc ${CVMFS_SOURCE_DIR}/ssl.cc