//# DOos.cc: Functions used to implement the DO functionality //# Copyright (C) 1999,2000,2001,2002 //# 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$ //# Includes #include #include #include #include #include #include #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN Vector DOos::isValidPathName (const Vector& pathName) { Vector result(pathName.nelements()); for (uInt i=0; i DOos::fileExists (const Vector& pathName, Bool follow) { Vector result(pathName.nelements()); for (uInt i=0; i DOos::fileType (const Vector& pathName, Bool follow) { Vector result(pathName.nelements()); for (uInt i=0; i DOos::fileNames (const String& directoryName, const String& fileNamePattern, const String& fileTypes, Bool all, Bool follow) { // Determine if and how to select on file type. Bool takeRegular = (fileTypes.contains ('r')); Bool takeDirectory = (fileTypes.contains ('d')); Bool takeSymLink = (fileTypes.contains ('s')); Bool takeReadable = (fileTypes.contains ('R')); Bool takeWritable = (fileTypes.contains ('W')); Bool takeExecutable = (fileTypes.contains ('X')); Bool checkType = (takeRegular || takeDirectory || takeSymLink); Bool checkAcc = (takeReadable || takeWritable || takeExecutable); Bool check = (checkType || checkAcc); // Set up the iterator. Default pattern is all. Vector result; Directory dir (directoryName); uInt n = 0; DirectoryIterator iter (dir); if (! fileNamePattern.empty()) { iter = DirectoryIterator (dir, Regex(Regex::fromPattern (fileNamePattern))); } // Iterate through the directory and add matching name to result. // Skip names starting with . if all is False. for (; !iter.pastEnd(); iter++) { String name = iter.name(); if (name[0] != '.' || all) { if (check) { File file(directoryName + '/' + name); if (checkType) { if (!( (takeRegular && file.isRegular (follow)) || (takeDirectory && file.isDirectory (follow)) || (takeSymLink && file.isSymLink()))) { continue; } } if (checkAcc) { if (!( (takeReadable && file.isReadable()) || (takeWritable && file.isWritable()) || (takeExecutable && file.isExecutable()))) { continue; } } } if (n >= result.nelements()) { result.resize (result.nelements() + 100, True); } result(n++) = name; } } result.resize (n, True); return result; } void DOos::makeDirectory (const Vector& directoryName, Bool makeParent) { for (uInt i=0; i parName(1); parName(0) = parent; makeDirectory (parName, makeParent); } } Directory dir(file); dir.create (False); } } Vector DOos::fullName (const Vector& fileName) { Vector result(fileName.nelements()); for (uInt i=0; i DOos::dirName (const Vector& fileName) { Vector result(fileName.nelements()); for (uInt i=0; i DOos::baseName (const Vector& fileName) { Vector result(fileName.nelements()); for (uInt i=0; i DOos::fileTime (const Vector& fileName, Int whichTime, Bool follow) { Vector result(fileName.nelements()); for (uInt i=0; i DOos::totalSize (const Vector& fileName, Bool follow) { Vector result(fileName.nelements()); for (uInt i=0; i DOos::freeSpace (const Vector& fileName, Bool follow) { Vector result(fileName.nelements()); for (uInt i=0; i (1, fileName), recursive, mustExist, follow); } void DOos::remove (const Vector& fileNames, Bool recursive, Bool mustExist, Bool follow) { uInt i; if (mustExist) { for (i=0; i DOos::lockInfo (const String& tableName) { Vector result(3); uInt pid; Bool permLocked; result(0) = LockFile::showLock (pid, permLocked, tableName + "/table.lock"); result(1) = pid; result(2) = (permLocked ? 1 : 0); return result; } } //# NAMESPACE CASACORE - END