LCOV - code coverage report
Current view: top level - casatools/Config - State.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 17 0.0 %
Date: 2024-10-10 11:40:37 Functions: 0 3 0.0 %

          Line data    Source code
       1             : #include <numeric>
       2             : #include <limits.h>
       3             : #include <unistd.h>
       4             : #include <stdexcept>
       5             : #include <casatools/Config/State.h>
       6             : 
       7             : namespace casatools {
       8             :     static bool shutting_down = false;
       9             : 
      10           0 :     State &get_state( )  {
      11           0 :         if ( shutting_down )
      12           0 :             throw std::runtime_error("casatools::get_state( ) called after shutdown initiated");
      13           0 :         if ( casacore::AppStateSource::fetch( ).initialized( ) == false )
      14           0 :             casacore::AppStateSource::initialize( new State );
      15           0 :         return dynamic_cast<State&>(casacore::AppStateSource::fetch( ));
      16             :     }
      17             : 
      18           0 :     void State::shutdown( ) {
      19           0 :         shutting_down = true;        
      20           0 :     }
      21             : 
      22           0 :     std::string State::resolve(const std::string &subdir) const {
      23             :         // This function overrides the base class casacore::AppState::resolve function to ensure
      24             :         // that when the subdir being resolved is found in the current working directory then a
      25             :         // fully qualified path is still returned. This allows the python level idiom:
      26             :         //
      27             :         //    file = 'casatestdata/some-ms.ms'
      28             :         //    resolved = ctsys.resolve(file)
      29             :         //    if file == resolved:
      30             :         //        # then file not found
      31             :         //        ...
      32             :         //
      33             :         // to still work. With this change, it is clear that the path was resolved because the
      34             :         // result is a fully qualified path.
      35             : 
      36             :         // return immediately if subdir is null string
      37           0 :         if ( subdir.size( ) <= 0 ) return subdir;
      38             : 
      39             :         // if subdir already resolves to a valid path, try to return a
      40             :         // fully qualified path...
      41             :         struct stat statbuf;
      42           0 :         if ( stat( subdir.c_str( ), &statbuf ) == 0 ) {
      43           0 :             if ( subdir[0] == '/' ) return subdir;
      44             :             char buf[PATH_MAX];
      45           0 :             if ( getcwd(buf,sizeof(buf)) ) {
      46           0 :                 return std::string(buf) + "/" + subdir;
      47             :             }
      48           0 :             return subdir;
      49             :         }
      50             : 
      51             :         // otherwise, if data path must be searched leave it
      52             :         // to the base class resolve method...
      53           0 :         return casacore::AppState::resolve( subdir );
      54             :     }
      55             : 
      56             : }

Generated by: LCOV version 1.16