Changeset 151 for trunk/lib


Ignore:
Timestamp:
Aug 13, 2006, 10:30:02 PM (15 years ago)
Author:
Jari Häkkinen
Message:

Fixes #50 and #58. Added checks that dirs exists and have proper permissions.

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility.cc

    r149 r151  
    2727#include <iostream> // remove this when 'blame' is removed
    2828#include <sstream>
     29#include <stdexcept>
    2930#include <string>
    3031#include <sys/param.h>
     
    3334namespace theplu{
    3435namespace svndigest{
     36
     37  int access_rights(const std::string& path, const std::string& bits)
     38  {
     39    if (int value=access(path.c_str(),F_OK)) {
     40      throw std::runtime_error(std::string("access_rights: ") + path +
     41                               "' does not exist.");
     42    }
     43    int mode=0;
     44    for (u_int i=0; i<bits.length(); i++)
     45      switch (bits[i]) {
     46          case 'r':
     47            mode|=R_OK;
     48            break;
     49          case 'w':
     50            mode|=W_OK;
     51            break;
     52          case 'x':
     53            mode|=X_OK;
     54            break;
     55      }
     56    return access(path.c_str(),mode);
     57  }
     58
    3559
    3660  std::string file_name(const std::string& full_path)
     
    4165    return name;
    4266  }
     67
    4368
    4469  void print_css(std::ostream& s)
     
    130155  {
    131156    char buffer[MAXPATHLEN];
    132     getcwd(buffer, MAXPATHLEN);
     157    if (!getcwd(buffer, MAXPATHLEN))
     158      throw std::runtime_error("Failed to get current working directory");
    133159    return std::string(buffer);
    134160  }
    135161
    136 
    137 
    138162}} // end of namespace svndigest and namespace theplu
  • trunk/lib/utility.h

    r149 r151  
    3636namespace theplu{
    3737namespace svndigest{
     38
     39  ///
     40  /// @brief Check if access permissions match \a mode. \a mode must
     41  /// be given as r, w, x, or combinations of these letters.
     42  ///
     43  /// @return On success (all requested permissions granted), zero
     44  /// is returned. On error (at least one bit in mode asked for a
     45  /// permission that is denied, or some other error occurred), -1
     46  /// is returned, and errno is set appropriately.
     47  ///
     48  /// @throw An std::runtime_error is thrown when checking for write
     49  /// permissions for a file/direcotry that does not exist.
     50  ///
     51  /// @see access(2)
     52  ///
     53  int access_rights(const std::string& path,const std::string& bits);
    3854
    3955  ///
Note: See TracChangeset for help on using the changeset viewer.