/usr/include/casacore/casa/OS/Directory.h is in casacore-dev 2.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | //# Directory.h: Get information about, and manipulate directories
//# Copyright (C) 1996,1997,1999
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
//# $Id$
#ifndef CASA_DIRECTORY_H
#define CASA_DIRECTORY_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/casa/OS/Path.h>
#include <casacore/casa/OS/File.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
template<class T> class Vector;
class Regex;
class String;
// <summary>
// Get information about, and manipulate directories
// </summary>
// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
// </reviewed>
// <use visibility=export>
// <prerequisite>
// <li> Basic knowledge of the UNIX file system
// <li> <linkto class=File>File</linkto>
// </prerequisite>
// <synopsis>
// Directory provides functions to manipulate and to get information about
// directories. The functions for getting information (like ownership, dates)
// about directories are inherited from the <linkto class=File>File</linkto>
// class.
// Directory itself provides functions to create, copy, move, or remove
// a directory. The file name can be a symbolic link resolving
// (eventually) to a directory.
// <p>
// A separate class <linkto class=DirectoryIterator>DirectoryIterator</linkto>
// allows one to traverse a directory to get the file names in it.
// </synopsis>
// <example>
// <srcblock>
// Directory dir("someDir");
// // Create directory someDir in the working directory.
// dir.create();
// cout << dir.nEntries(); // #entries
// // Assign to another directory.
// dir = Directory("otherDir");
// // Remove the directory and its contents.
// dir.removeRecursive();
// </srcblock>
// </example>
// <motivation>
// Provide functions for manipulating and getting information
// about directories.
// </motivation>
class Directory: public File
{
public:
// Sets the path on the current working directory
Directory();
// Create a directory object for a file with the given path name.
// An exception is thrown if the directory is illegal, i.e. if it does
// not exist as a directory or symbolic link or if cannot be created.
// Note that the directory is not created if it does not exist yet.
// This can be done using the function create.
// <br>
// When the given path name is a symbolic link, the symbolic link
// is resolved (recursively) and the resulting directory name is used
// instead.
// <group>
Directory (const Path& name);
Directory (const String& name);
Directory (const File& name);
// </group>
// Copy constructor (copy semantics).
Directory (const Directory& that);
~Directory();
// Assignment (copy semantics).
Directory& operator= (const Directory& that);
// Check if directory is empty.
// If the directory does not exist, an exception will be thrown.
Bool isEmpty() const;
// Return the number of entries in the directory (not counting . and ..).
// If the directory does not exist, an exception will be thrown.
uInt nEntries() const;
// Get the amount of free space (in bytes) on the file system this
// directory is on. When the directory path is a symbolic link, that
// link is resolved first.
// <group>
Double freeSpace() const;
uInt freeSpaceInMB() const;
// </group>
// Create the directory.
// <br>If the directory exists and overwrite=True, it will be removed
// (recursively). Otherwise an exception is thrown.
void create (Bool overwrite = True);
// Remove a directory.
// An exception is thrown if the directory is not empty.
// If a symbolic link is given, the link chain pointing to the directory
// will also be removed.
void remove();
// Remove all files in the directory except subdirectories.
// The directory itself is not removed.
void removeFiles();
// Remove the directory and its contents (recursively in all
// subdirectories).
// If <src>keepDir==True</src>, the directory itself is kept
//(to keep properties like placement on Lustre).
void removeRecursive (Bool keepDir = False);
// Copy the directory and its contents (recursively) to the target
// path using the system command cp -r.
// If the target already exists (as a file, directory or symlink),
// and overwrite=True, it will first be removed.
// The target directory is created and the data in the source
// directory is copied to the new directory.
// <br>An exception is thrown if:
// <br>- the target directory is not writable
// <br>- or the target already exists and overwrite!=True
// <note role=caution>
// 1. The behavior of this copy function is different from cp when the
// target directory already exists. Cp copies the source to a
// subdirectory of the target, while copy recreates the target.
// <br>2. When a readonly file is copied, <src>cp</src> the resulting
// file is also readonly. Therefore <src>chmod</src> is used to
// set user write permission after the copy.
// The flag <src>setUserWritePermission</src> can be set to False
// when that should not be done.
// </note>
// <group>
void copy (const Path& target, Bool overwrite = True,
Bool setUserWritePermission = True) const;
void copy (const String& target, Bool overwrite = True,
Bool setUserWritePermission = True) const;
// </group>
// Copy a directory recursively in a manual way.
// This is used in a copy using the system command is not possible
// (like on the Cray XT3).
void copyRecursive (const String& target) const;
// Move the directory to the target path using the system command mv.
// If the target already exists (as a file, directory or symlink),
// and overwrite=True, it will first be removed.
// The source directory is moved (thus renamed) to the target.
// <br>An exception is thrown if:
// <br>- the target directory is not writable
// <br>- or the target already exists and overwrite!=True
// <note role=caution>
// The behavior of this move function is different from mv when the
// target directory already exists. Mv moves the source to a
// subdirectory of the target, while move recreates the target.
// </note>
// <group>
void move (const Path& target, Bool overwrite = True);
void move (const String& target, Bool overwrite = True);
// </group>
// Find all files which whose names match <src>regex</src>. You
// can do this recursively (default) or not. Note that the
// matching is a regular expression match, not a shell file-expansion
// match. However, a shell file pattern can be converted to a regexp
// using the function <linkto class=Regex>Regex::fromPattern</linkto>.
// <src>Regex::fromString</src> allows one to convert a file name
// to a regexp and to use this function for eact file name matching.
// <br>To match the semantics of the unix <src>find</src> command,
// symbolic links are not followed by default, but this behavior
// can be over-ridden.
Vector<String> find (const Regex& regexp, Bool followSymLinks=False,
Bool recursive=True) const;
// For each element of <src>files</src>, find all file names matching
// it using shell file-expansion rules. Return the list of all matched files
// as absolute path + file names. You may optionally drop the path and just return
// the file names. Note tha if <src>files(i)</src> contains a path as well as a file
// name, no matching is done on the path, just the trailing file name.
// Throws an AipsError if the shell pattern is illegal.
static Vector<String> shellExpand (const Vector<String>& files, Bool stripPath=False);
// Return the total size of everything in the Directory. If the Directory
// does not exist, an exception will be thrown.
virtual Int64 size() const;
//Check if a directory is mounted via NFS or not.
Bool isNFSMounted() const;
private:
// Check if the path defines a directory.
// Also resolve possible symlinks.
void checkPath();
// This variable is used when a symbolic link is given to be
// a directory.
File itsFile;
};
inline void Directory::copy (const String& target, Bool overwrite,
Bool setUserWritePermission) const
{
copy (Path(target), overwrite, setUserWritePermission);
}
inline void Directory::move (const String& target, Bool overwrite)
{
move (Path(target), overwrite);
}
inline uInt Directory::freeSpaceInMB() const
{
return uInt (0.5 + freeSpace() / (1024*1024));
}
} //# NAMESPACE CASACORE - END
#endif
|