diff --git a/src/XrdApps.cmake b/src/XrdApps.cmake index df2134ce3d2..f342892adfd 100644 --- a/src/XrdApps.cmake +++ b/src/XrdApps.cmake @@ -1,5 +1,3 @@ - - #------------------------------------------------------------------------------- # Modules #------------------------------------------------------------------------------- @@ -210,10 +208,16 @@ add_executable( xrdclcacheclean XrdApps/XrdClJCachePlugin/app/XrdClCacheCleaner.cc ) -target_link_libraries( - xrdclcacheclean - stdc++fs -) +if ( MacOSX ) + target_link_libraries( + xrdclcacheclean + ) +else() + target_link_libraries( + xrdclcacheclean + stdc++fs + ) +endif() #------------------------------------------------------------------------------- # XrdClJCachePlugin library @@ -237,10 +241,13 @@ add_library( XrdApps/XrdClJCachePlugin/cleaner/Cleaner.hh ) -target_include_directories( ${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE "${CMAKE_SOURCE_DIR}/src/XrdApps/XrdClJCachePlugin/" ) +target_include_directories( ${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE "${CMAKE_SOURCE_DIR}/src/XrdApps/XrdClJCachePlugin/" ) -target_link_libraries(${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE XrdCl stdc++fs) - +if ( MacOSX ) + target_link_libraries(${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE XrdCl OpenSSL::SSL) +else () + target_link_libraries(${LIB_XRDCL_JCACHE_PLUGIN} PRIVATE XrdCl stdc++fs OpenSSL::SSL) +endif () #------------------------------------------------------------------------------- # Install diff --git a/src/XrdApps/XrdClJCachePlugin/cache/Journal.cc b/src/XrdApps/XrdClJCachePlugin/cache/Journal.cc index 466af684d56..e822eb0f94e 100644 --- a/src/XrdApps/XrdClJCachePlugin/cache/Journal.cc +++ b/src/XrdApps/XrdClJCachePlugin/cache/Journal.cc @@ -35,6 +35,12 @@ #include /*----------------------------------------------------------------------------*/ +#ifdef __APPLE__ +#include +#define pread64 pread +#define pwrite64 pwrite +#endif + //------------------------------------------------------------------------------ //! Journal Constructor //------------------------------------------------------------------------------ @@ -96,7 +102,7 @@ void Journal::read_jheader() { if (jheader.mtime) { if (exists) { // we only compare if there was a header in the journal - if ((abs(fheader.mtime - jheader.mtime) > 1) || + if ((abs((int)(fheader.mtime - jheader.mtime)) > 1) || (fheader.mtime_nsec != jheader.mtime_nsec) || (jheader.filesize && (fheader.filesize != jheader.filesize))) { std::cerr << "warning: remote file change detected - purging path:" @@ -183,7 +189,7 @@ int Journal::attach(const std::string &lpath, uint64_t mtime, } } } - if ((fd == -1)) { + if (fd == -1) { // need to open the file size_t tries = 0; @@ -462,7 +468,11 @@ int Journal::sync() { if (fd < 0) { return -1; } +#ifdef __APPLE__ + return ::fsync(fd); +#else return ::fdatasync(fd); +#endif } //------------------------------------------------------------------------------ diff --git a/src/XrdApps/XrdClJCachePlugin/cleaner/Cleaner.cc b/src/XrdApps/XrdClJCachePlugin/cleaner/Cleaner.cc index 4ca1ef0a659..68c16a3dcb9 100644 --- a/src/XrdApps/XrdClJCachePlugin/cleaner/Cleaner.cc +++ b/src/XrdApps/XrdClJCachePlugin/cleaner/Cleaner.cc @@ -23,7 +23,7 @@ /*----------------------------------------------------------------------------*/ #include "cleaner/Cleaner.hh" -#include +#include /*----------------------------------------------------------------------------*/ namespace fs = std::filesystem; @@ -64,13 +64,25 @@ long long Cleaner::getDirectorySize(const fs::path &directory, bool scan) { } } } else { - struct statfs stat; + struct statvfs fs_info; - if (statfs(directory.c_str(), &stat) != 0) { + if (statvfs(directory.c_str(), &fs_info) != 0) { mLog->Error(1, - "JCache:Cleaner: failed to get directory size using statfs."); + "JCache:Cleaner: failed to get directory size using statvfs."); return 0; } + // Calculate total space in bytes + unsigned long long total_blocks = fs_info.f_blocks; + unsigned long long block_size = fs_info.f_bsize; + unsigned long long total_space = total_blocks * block_size; + + // Calculate free space in bytes + unsigned long long free_blocks = fs_info.f_bfree; + unsigned long long free_space = free_blocks * block_size; + + // Calculate used space in bytes + unsigned long long used_space = total_space - free_space; + totalSize = used_space; } return totalSize; } @@ -143,4 +155,4 @@ void Cleaner::cleanDirectory(const fs::path &directory, long long highWatermark, } } } -} // namespace JCache \ No newline at end of file +} // namespace JCache diff --git a/src/XrdApps/XrdClJCachePlugin/file/Art.hh b/src/XrdApps/XrdClJCachePlugin/file/Art.hh index 86a24ef83e0..5232887259f 100644 --- a/src/XrdApps/XrdClJCachePlugin/file/Art.hh +++ b/src/XrdApps/XrdClJCachePlugin/file/Art.hh @@ -100,7 +100,7 @@ public: << runtime << "s ]" << std::endl; } - void drawCurve(const std::vector &data, double interval, + void drawCurve(const std::vector &data, double interval, double runtime) { std::vector newdata; if (interval == 0) { diff --git a/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh b/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh index 8718334d694..97ba3fca97d 100644 --- a/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh +++ b/src/XrdApps/XrdClJCachePlugin/file/XrdClJCacheFile.hh @@ -82,14 +82,14 @@ public: //---------------------------------------------------------------------------- virtual XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, - uint16_t timeout); + uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief Close a file //! @param handler Response handler //! @param timeout Timeout in seconds //---------------------------------------------------------------------------- - virtual XRootDStatus Close(ResponseHandler *handler, uint16_t timeout); + virtual XRootDStatus Close(ResponseHandler *handler, uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief Stat a file @@ -98,7 +98,7 @@ public: //! @param timeout Timeout in seconds //---------------------------------------------------------------------------- virtual XRootDStatus Stat(bool force, ResponseHandler *handler, - uint16_t timeout); + uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief Read @@ -109,7 +109,7 @@ public: //! @param timeout Timeout in seconds //---------------------------------------------------------------------------- virtual XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, - ResponseHandler *handler, uint16_t timeout); + ResponseHandler *handler, uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief Write @@ -120,14 +120,14 @@ public: //! @param timeout Timeout in seconds //---------------------------------------------------------------------------- virtual XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, - ResponseHandler *handler, uint16_t timeout); + ResponseHandler *handler, uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief Sync //! @param handler Response handler //! @param timeout Timeout in seconds //---------------------------------------------------------------------------- - virtual XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout); + virtual XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief Truncate @@ -136,7 +136,7 @@ public: //! @param timeout Timeout in seconds //---------------------------------------------------------------------------- virtual XRootDStatus Truncate(uint64_t size, ResponseHandler *handler, - uint16_t timeout); + uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief VectorRead @@ -146,7 +146,7 @@ public: //! @param timeout Timeout in seconds //---------------------------------------------------------------------------- virtual XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, - ResponseHandler *handler, uint16_t timeout); + ResponseHandler *handler, uint16_t timeout) override; //------------------------------------------------------------------------ //! @brief PgRead @@ -181,29 +181,29 @@ public: //! @param timeout Timeout in seconds //------------------------------------------------------------------------ virtual XRootDStatus Fcntl(const Buffer &arg, ResponseHandler *handler, - uint16_t timeout); + uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief Visa //! @param handler Response handler //! @param timeout Timeout in seconds //---------------------------------------------------------------------------- - virtual XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout); + virtual XRootDStatus Visa(ResponseHandler *handler, uint16_t timeout) override; //---------------------------------------------------------------------------- //! @brief check if file is open //---------------------------------------------------------------------------- - virtual bool IsOpen() const; + virtual bool IsOpen() const override; //---------------------------------------------------------------------------- //! @see XrdCl::File::SetProperty //---------------------------------------------------------------------------- - virtual bool SetProperty(const std::string &name, const std::string &value); + virtual bool SetProperty(const std::string &name, const std::string &value) override; //---------------------------------------------------------------------------- //! @see XrdCl::File::GetProperty //---------------------------------------------------------------------------- - virtual bool GetProperty(const std::string &name, std::string &value) const; + virtual bool GetProperty(const std::string &name, std::string &value) const override; //---------------------------------------------------------------------------- //! @brief validate the local cache