Ignore:
Timestamp:
08/11/11 23:09:13 (13 years ago)
Author:
tbretz
Message:
Implemented a new determination fo run-number after noon in the fadctrl; created the possibility to add the date to the raw-data path; allow to set the path as program option; for all this moved some code from the datalogger to DimWriteStatistics
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/DimWriteStatistics.cc

    r11534 r11893  
    1010#include <sys/statvfs.h> //for getting disk free space
    1111#include <sys/stat.h>    //for getting files sizes
     12
     13#include <boost/filesystem.hpp>
    1214
    1315#include "Time.h"
     
    8890
    8991     return -1;
     92}
     93
     94// --------------------------------------------------------------------------
     95//
     96//! Check if a given path exists
     97//! @param path the path to be checked
     98//! @return whether or not the given path exists
     99//
     100bool DimWriteStatistics::DoesPathExist(const string &path, MessageImp &log)
     101{
     102    namespace fs = boost::filesystem;
     103
     104    const fs::path fullPath = fs::system_complete(fs::path(path));
     105
     106    if (!fs::exists(fullPath))
     107       return false;
     108
     109    if (!fs::is_directory(fullPath))
     110    {
     111        log.Error("Path given for checking '" + path + "' designate a file name. Please provide a path name only");
     112        return false;
     113    }
     114
     115    if (access(path.c_str(), R_OK|W_OK|X_OK) != 0)
     116    {
     117        log.Error("Missing read, write or execute permissions on directory '" + path + "'");
     118        return false;
     119    }
     120
     121    return true;
     122}
     123
     124// --------------------------------------------------------------------------
     125//
     126//! Check if a given path exists
     127//! @param path the path to be checked
     128//! @return whether or not the creation has been successfull
     129//
     130void DimWriteStatistics::CreateDirectory(string path)
     131{
     132    namespace fs = boost::filesystem;
     133
     134    //remove last '/', if present
     135    if (path[path.size()-1] == '/')
     136        path = path.substr(0, path.size()-1);
     137
     138    //create boost path
     139    const fs::path fullPath = fs::system_complete(fs::path(path));
     140
     141    //if path does not exist, check if upper levels exist already
     142    if (fs::exists(fullPath))
     143    {
     144        //if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist)
     145        if (fs::is_directory(fullPath))
     146            return;
     147
     148        throw runtime_error("Path to be created is a file  '" + path + "'");
     149    }
     150
     151    // we're hitting "/", which SHOULD have existed...
     152    if (path.size() <= 1)
     153        throw runtime_error("Path to be created looks suspicious '"+path+"'");
     154
     155    CreateDirectory(path.substr(0, path.find_last_of('/')));
     156
     157    //path does not exist, and upper level have been created already by recusrion.
     158    const mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes
     159
     160    if (mkdir(path.c_str(), rightsMask)==0)
     161        return;
     162
     163    ostringstream str;
     164    str << "mkdir() failed for '" << path << "': " << strerror(errno) << " [errno=" << errno << "]";
     165    throw runtime_error(str.str());
    90166}
    91167
Note: See TracChangeset for help on using the changeset viewer.