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

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

trac moved to new location.

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