source: trunk/yat/utility/FileUtil.h @ 1486

Last change on this file since 1486 was 1486, checked in by Jari Häkkinen, 13 years ago

Addresses #436.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
RevLine 
[710]1#ifndef _theplu_yat_utility_fileutil_
2#define _theplu_yat_utility_fileutil_
[680]3
[58]4// $Id: FileUtil.h 1486 2008-09-09 21:17:19Z jari $
5
[570]6/*
[831]7  Copyright (C) 2004 Jari Häkkinen
8  Copyright (C) 2005 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2006 Jari Häkkinen
[1275]10  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
11  Copyright (C) 2008 Peter Johansson
[570]12
[1437]13  This file is part of the yat library, http://dev.thep.lu.se/yat
[570]14
[675]15  The yat library is free software; you can redistribute it and/or
16  modify it under the terms of the GNU General Public License as
[1486]17  published by the Free Software Foundation; either version 3 of the
[675]18  License, or (at your option) any later version.
[570]19
[675]20  The yat library is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
[570]23  General Public License for more details.
24
25  You should have received a copy of the GNU General Public License
26  along with this program; if not, write to the Free Software
27  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28  02111-1307, USA.
29*/
30
[709]31#include "Exception.h"
32
[58]33#include <string>
[709]34#include <sys/stat.h>
[360]35#include <unistd.h>
36
[58]37namespace theplu {
[680]38namespace yat {
[301]39namespace utility {
[58]40
41  ///
42  ///
[767]43  /// @brief Checking file/directory existence and access permissions.
44  ///
45  /// FileUtil is a wrapper to access(2) and stat(2).
46  ///
[710]47  class FileUtil {
[58]48  public:
49
50    ///
[711]51    /// \brief Constructor, copies \a path only
[709]52    ///
[710]53    explicit FileUtil(const std::string& path);
[709]54
55    ///
[711]56    /// \brief Check file/directory permissions
[709]57    ///
[58]58    /// Check if access permissions match \a mode. \a mode must be
[1207]59    /// given as r, w, x, d, or combinations of these letters. The check
60    /// is performed at call time.
[58]61    ///
[711]62    /// \note Checking permissions on a non-existent file will match
63    /// the permissions against the parent directory, but only the
64    /// parent directory. This means that when the parent directory
65    /// does not exist then fail is returned.
[709]66    ///
[711]67    /// \return On success (all requested permissions granted), zero
[58]68    /// is returned. On error (at least one bit in mode asked for a
69    /// permission that is denied, or some other error occurred), -1
70    /// is returned, and errno is set appropriately.
71    ///
[1207]72    /// \exception IO_error if exists() throws.
73    /// \exception std::invalid_argument if \a bits contain other
74    /// character than r, w, x, or d.
[711]75    ///
76    int permissions(const std::string& bits) const;
[58]77
[360]78    ///
[711]79    /// \brief Check whether \a file exists.
[360]80    ///
[711]81    /// The check for the file is done when calling this function.
[360]82    ///
[711]83    /// \return True if \a file exists, false otherwise.
84    ///
85    /// \exception IO_error if underlying stat(2) call fails in other
86    /// ways than that file does not exist.
87    ///
88    /// \see stat(2)
89    ///
90    bool exists(void) const;
[709]91
[360]92    ///
[711]93    /// \brief Get path associated with the object.
[497]94    ///
[709]95    const std::string& path(void) const;
96
97  private:
98    ///
99    /// \brief The copy constructor, not implemented
100    ///
[710]101    FileUtil(const FileUtil&);
[709]102
103    std::string path_;
[58]104  };
105
[687]106}}} // of namespace utility, yat, and theplu
[58]107
108#endif
Note: See TracBrowser for help on using the repository browser.