Doxygen
Loading...
Searching...
No Matches
Dir Class Referencefinal

Class representing a directory in the file system. More...

#include <src/dir.h>

Classes

struct  Private

Public Member Functions

 Dir ()
 Dir (const std::string &path)
 Dir (const Dir &d)
Diroperator= (const Dir &d)
 Dir (Dir &&d)
Diroperator= (Dir &&d)
 ~Dir ()
void setPath (const std::string &path)
std::string path () const
DirIterator iterator () const
bool empty (const std::string &subdir) const
bool exists () const
std::string filePath (const std::string &path, bool acceptsAbsPath=true) const
bool exists (const std::string &path, bool acceptsAbsPath=true) const
bool mkdir (const std::string &path, bool acceptsAbsPath=true) const
bool rmdir (const std::string &path, bool acceptsAbsPath=true) const
bool remove (const std::string &path, bool acceptsAbsPath=true) const
bool rename (const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
bool copy (const std::string &src, const std::string &dest, bool acceptsAbsPath=true) const
std::string absPath () const
bool isRelative () const

Static Public Member Functions

static bool isRelativePath (const std::string &path)
static std::string currentDirPath ()
static bool setCurrent (const std::string &path)
static std::string cleanDirPath (const std::string &path)

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Class representing a directory in the file system.

Definition at line 72 of file dir.h.

Constructor & Destructor Documentation

◆ Dir() [1/4]

Dir::Dir ( )

Definition at line 195 of file dir.cpp.

195 : p(std::make_unique<Private>())
196{
197 std::error_code ec;
198 p->path = fs::current_path(ec);
199}
std::unique_ptr< Private > p
Definition dir.h:108

References p.

Referenced by Dir(), Dir(), operator=(), and operator=().

◆ Dir() [2/4]

Dir::Dir ( const std::string & path)

Definition at line 226 of file dir.cpp.

226 : p(std::make_unique<Private>())
227{
228 setPath(path);
229}
void setPath(const std::string &path)
Definition dir.cpp:235
std::string path() const
Definition dir.cpp:240

References p, path(), and setPath().

◆ Dir() [3/4]

Dir::Dir ( const Dir & d)

Definition at line 201 of file dir.cpp.

201 : p(std::make_unique<Private>())
202{
203 p->path = d.p->path;
204}

References Dir(), and p.

◆ Dir() [4/4]

Dir::Dir ( Dir && d)

Definition at line 215 of file dir.cpp.

215 : p(std::make_unique<Private>())
216{
217 std::exchange(p->path,d.p->path);
218}

References Dir(), and p.

◆ ~Dir()

Dir::~Dir ( )

Definition at line 231 of file dir.cpp.

232{
233}

Member Function Documentation

◆ absPath()

std::string Dir::absPath ( ) const

Definition at line 370 of file dir.cpp.

371{
372 std::error_code ec;
373 std::string result = fs::absolute(p->path,ec).string();
374 correctPath(result);
375 return result;
376}
static void correctPath(std::string &s)
Definition dir.cpp:250

References correctPath(), and p.

Referenced by Htags::execute(), PerlModGenerator::generate(), FormulaManager::generateImages(), parseInput(), Htags::path2URL(), RTFGenerator::preProcessFileInplace(), writeDotGraphFromFile(), writeDotImageMapFromFile(), and DotGraph::writeGraph().

◆ cleanDirPath()

std::string Dir::cleanDirPath ( const std::string & path)
static

Definition at line 363 of file dir.cpp.

364{
365 std::string result = fs::path(path).lexically_normal().string();
366 correctPath(result);
367 return result;
368}

References correctPath(), and path().

Referenced by FileNameLinkedMap::findFileDef(), resolveSymlink(), and FileNameLinkedMap::showFileDefMatches().

◆ copy()

bool Dir::copy ( const std::string & src,
const std::string & dest,
bool acceptsAbsPath = true ) const

Definition at line 336 of file dir.cpp.

337{
338 const auto &copyOptions = fs::copy_options::overwrite_existing;
339 std::error_code ec, ec_perm;
340 std::string sn = filePath(srcName,acceptsAbsPath);
341 std::string dn = filePath(dstName,acceptsAbsPath);
342 fs::copy(sn,dn,copyOptions,ec);
343 // make sure the destination is writable for the owner (see issue #11600)
344 fs::permissions(dn, fs::perms::owner_write, fs::perm_options::add, ec_perm);
345 return !ec;
346}
std::string filePath(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:286

References filePath().

◆ currentDirPath()

std::string Dir::currentDirPath ( )
static

◆ empty()

bool Dir::empty ( const std::string & subdir) const

Definition at line 269 of file dir.cpp.

270{
271 fs::path pth = path();
272 pth /= subdir;
273 return fs::is_empty(pth);
274}

References path().

Referenced by clearSubDirs().

◆ exists() [1/2]

◆ exists() [2/2]

bool Dir::exists ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 255 of file dir.cpp.

256{
257 std::string result = filePath(path,acceptsAbsPath);
258 std::error_code ec;
259 bool exist = fs::exists(fs::path(result),ec);
260 return !ec && exist;
261}

References filePath(), and path().

◆ filePath()

std::string Dir::filePath ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 286 of file dir.cpp.

287{
288 std::string result;
289 if (acceptsAbsPath && !isRelativePath(path))
290 {
291 result = path;
292 }
293 else
294 {
295 result = (p->path / path).string();
296 }
297 correctPath(result);
298 return result;
299}
static bool isRelativePath(const std::string &path)
Definition dir.cpp:281

References correctPath(), isRelativePath(), p, and path().

Referenced by copy(), exists(), mkdir(), preProcessFile(), RTFGenerator::preProcessFileInplace(), remove(), and rename().

◆ isRelative()

bool Dir::isRelative ( ) const

Definition at line 276 of file dir.cpp.

277{
278 return isRelativePath(p->path.string());
279}

References isRelativePath(), and p.

◆ isRelativePath()

bool Dir::isRelativePath ( const std::string & path)
static

Definition at line 281 of file dir.cpp.

282{
283 return fs::path(path).is_relative();
284}

References path().

Referenced by filePath(), and isRelative().

◆ iterator()

DirIterator Dir::iterator ( ) const

Definition at line 245 of file dir.cpp.

246{
247 return DirIterator(p->path.string());
248}

References p.

Referenced by readDir().

◆ mkdir()

bool Dir::mkdir ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 301 of file dir.cpp.

302{
303 std::error_code ec;
304 std::string result = filePath(path,acceptsAbsPath);
305 if (exists(path,acceptsAbsPath))
306 {
307 return true;
308 }
309 else
310 {
311 return fs::create_directory(result,ec);
312 }
313}
bool exists() const
Definition dir.cpp:263

References exists(), filePath(), and path().

Referenced by PerlModGenerator::createOutputDir(), createOutputDirectory(), createSubDirs(), generateDEF(), generateOutput(), CitationManager::generatePage(), DocbookGenerator::init(), HtmlGenerator::init(), LatexGenerator::init(), ManGenerator::init(), RTFGenerator::init(), initWarningFormat(), and parseInput().

◆ operator=() [1/2]

Dir & Dir::operator= ( const Dir & d)

Definition at line 206 of file dir.cpp.

207{
208 if (&d!=this)
209 {
210 p->path = d.p->path;
211 }
212 return *this;
213}

References Dir(), and p.

◆ operator=() [2/2]

Dir & Dir::operator= ( Dir && d)

Definition at line 220 of file dir.cpp.

221{
222 std::exchange(p->path,d.p->path);
223 return *this;
224}

References Dir(), and p.

◆ path()

std::string Dir::path ( ) const

Definition at line 240 of file dir.cpp.

241{
242 return p->path.string();
243}

References p.

Referenced by cleanDirPath(), Dir(), empty(), exists(), filePath(), isRelativePath(), mkdir(), DotGraph::prepareDotFile(), remove(), rmdir(), setCurrent(), and setPath().

◆ remove()

◆ rename()

bool Dir::rename ( const std::string & orgName,
const std::string & newName,
bool acceptsAbsPath = true ) const

Definition at line 327 of file dir.cpp.

328{
329 std::error_code ec;
330 std::string fn1 = filePath(orgName,acceptsAbsPath);
331 std::string fn2 = filePath(newName,acceptsAbsPath);
332 fs::rename(fn1,fn2,ec);
333 return !ec;
334}

References filePath().

Referenced by openOutputFile(), RTFGenerator::preProcessFileInplace(), resetPDFSize(), DotFilePatcher::run(), and DotRunner::run().

◆ rmdir()

bool Dir::rmdir ( const std::string & path,
bool acceptsAbsPath = true ) const

Definition at line 315 of file dir.cpp.

316{
317 return remove(path,acceptsAbsPath);
318}
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:320

References path(), and remove().

Referenced by clearSubDirs(), and CitationManager::generatePage().

◆ setCurrent()

bool Dir::setCurrent ( const std::string & path)
static

◆ setPath()

void Dir::setPath ( const std::string & path)

Definition at line 235 of file dir.cpp.

236{
237 p->path = path;
238}

References p, and path().

Referenced by PerlModGenerator::createOutputDir(), Dir(), Htags::execute(), and parseInput().

Member Data Documentation

◆ p

std::unique_ptr<Private> Dir::p
private

The documentation for this class was generated from the following files: