Changeset 1207 for trunk/yat/utility


Ignore:
Timestamp:
Mar 6, 2008, 12:56:42 AM (14 years ago)
Author:
Peter
Message:

fixes #282

Location:
trunk/yat/utility
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/FileUtil.cc

    r1001 r1207  
    2828#include <cerrno>
    2929#include <iostream>
     30#include <stdexcept>
    3031#include <string>
    3132
     
    5455
    5556    int mode=0;
     57    bool ok = true;
    5658    for (u_int i=0; i<bits.length(); i++)
    5759      switch (bits[i]) {
    58           case 'r':
     60          case 'r':
    5961            mode|=R_OK;
    6062            break;
     
    6567            mode|=X_OK;
    6668            break;
     69          case 'd':
     70            struct stat nodestat;
     71            stat(tryme.c_str(),&nodestat);
     72            if (!S_ISDIR(nodestat.st_mode))
     73              ok = false;
     74            break;
     75          default:
     76            throw std::invalid_argument("FileUtil::permission: "+bits);
    6777      }
    68 
     78    if (!ok)
     79      return -1;
    6980    return access(tryme.c_str(),mode);
    7081  }
  • trunk/yat/utility/FileUtil.h

    r1000 r1207  
    5656    ///
    5757    /// Check if access permissions match \a mode. \a mode must be
    58     /// given as r, w, x, or combinations of these letters. The check
    59     /// is performed att call time.
     58    /// given as r, w, x, d, or combinations of these letters. The check
     59    /// is performed at call time.
    6060    ///
    6161    /// \note Checking permissions on a non-existent file will match
     
    6969    /// is returned, and errno is set appropriately.
    7070    ///
    71     /// \exception Throws whatever exists() throws.
     71    /// \exception IO_error if exists() throws.
     72    /// \exception std::invalid_argument if \a bits contain other
     73    /// character than r, w, x, or d.
    7274    ///
    7375    int permissions(const std::string& bits) const;
  • trunk/yat/utility/OptionFile.cc

    r1179 r1207  
    6868          throw cmd_error(ss.str());
    6969        }
     70        else if (*iter=='d' && fu.permissions("d")){
     71          std::stringstream ss;
     72          ss << value()
     73             << "': Not a directory";
     74          throw cmd_error(ss.str());
     75        }
    7076      }
    7177      std::stringstream ss;
Note: See TracChangeset for help on using the changeset viewer.