Changeset 1207


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

fixes #282

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/fileutil_test.cc

    r1001 r1207  
    6060      *error << "\trx permissions on " << file.path() << std::endl;
    6161    ok&=!testval;
     62    if (!(testval=file.permissions("d")))
     63      *error << "\td permissions on " << file.path() << std::endl;
     64    ok&=!testval;
    6265  }
    6366  catch (utility::IO_error e) {
     
    8588      *error << "\tw permission on " << file.path() << std::endl;
    8689    ok&=!testval; // 'w' on non-existent file ok if directory writeable
     90    if (!(testval=file.permissions("d")))
     91      *error << "\td permission on " << file.path() << std::endl;
     92    ok&=!testval;
    8793  }
    8894  catch (utility::IO_error e) {
     
    109115      *error << "\tw permission on " << file.path() << std::endl;
    110116    ok&=!testval; // 'w' on non-existent file ok if directory writeable
     117    if (!(testval=file.permissions("d")))
     118      *error << "\td permission on " << file.path() << std::endl;
     119    ok&=!testval;
    111120  }
    112121  catch (utility::IO_error e) {
     
    134143      *error << "\tw permission failed on " << file.path() << std::endl;
    135144    ok&=testval;
     145    if (testval=file.permissions("d"))
     146      *error << "\td permission failed on " << file.path() << std::endl;
     147    ok&=testval;
    136148  }
    137149  catch (utility::IO_error e) {
     
    160172  }
    161173
     174  try {
     175    *error << "FileUtil Test 6" << std::endl;
     176    utility::FileUtil file("fileutil_test.cc");
     177    file.permissions("rxwa"); // should throw
     178    ok = false;
     179  }
     180  catch (std::invalid_argument& e) {
     181    *error << "Expected exception thrown with what: " << e.what() << std::endl;
     182  }
     183
     184 
    162185 
    163186
  • 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.