Ninja
Public Types | Public Member Functions | List of all members
DiskInterface Struct Referenceabstract

Interface for accessing the disk. More...

#include <disk_interface.h>

Inheritance diagram for DiskInterface:
Inheritance graph
[legend]

Public Types

enum  Status { Okay, NotFound, OtherError }
 Result of ReadFile. More...
 

Public Member Functions

virtual bool MakeDir (const string &path)=0
 Create a directory, returning false on failure. More...
 
bool MakeDirs (const string &path)
 Create all the parent directories for path; like mkdir -p basename path. More...
 
virtual Status ReadFile (const string &path, string *contents, string *err)=0
 Read and store in given string. More...
 
virtual int RemoveFile (const string &path)=0
 Remove the file named path. More...
 
virtual TimeStamp Stat (const string &path, string *err) const =0
 stat() a file, returning the mtime, or 0 if missing and -1 on other errors. More...
 
virtual bool WriteFile (const string &path, const string &contents)=0
 Create a file, with the specified name and contents Returns true on success, false on failure. More...
 

Detailed Description

Interface for accessing the disk.

Abstract so it can be mocked out for tests. The real implementation is RealDiskInterface.

Definition at line 46 of file disk_interface.h.

Member Enumeration Documentation

◆ Status

enum FileReader::Status
inherited

Result of ReadFile.

Enumerator
Okay 
NotFound 
OtherError 

Definition at line 30 of file disk_interface.h.

Member Function Documentation

◆ MakeDir()

virtual bool DiskInterface::MakeDir ( const string &  path)
pure virtual

Create a directory, returning false on failure.

Implemented in VirtualFileSystem, and RealDiskInterface.

Referenced by MakeDirs().

◆ MakeDirs()

bool DiskInterface::MakeDirs ( const string &  path)

Create all the parent directories for path; like mkdir -p basename path.

Definition at line 134 of file disk_interface.cc.

References Error(), MakeDir(), and Stat().

Referenced by Builder::StartEdge().

◆ ReadFile()

virtual Status FileReader::ReadFile ( const string &  path,
string *  contents,
string *  err 
)
pure virtualinherited

Read and store in given string.

On success, return Okay. On error, return another Status and fill |err|.

Implemented in VirtualFileSystem, and RealDiskInterface.

Referenced by Builder::ExtractDeps(), ManifestParser::Load(), and ImplicitDepLoader::LoadDepFile().

◆ RemoveFile()

virtual int DiskInterface::RemoveFile ( const string &  path)
pure virtual

Remove the file named path.

It behaves like 'rm -f path' so no errors are reported if it does not exists.

Returns
0 if the file has been removed, 1 if the file does not exist, and -1 if an error occurs.

Implemented in VirtualFileSystem, and RealDiskInterface.

Referenced by Builder::Cleanup(), Builder::ExtractDeps(), Builder::FinishCommand(), and Cleaner::RemoveFile().

◆ Stat()

virtual TimeStamp DiskInterface::Stat ( const string &  path,
string *  err 
) const
pure virtual

stat() a file, returning the mtime, or 0 if missing and -1 on other errors.

Implemented in VirtualFileSystem, and RealDiskInterface.

Referenced by Builder::Cleanup(), Cleaner::FileExists(), Builder::FinishCommand(), MakeDirs(), and Node::Stat().

◆ WriteFile()

virtual bool DiskInterface::WriteFile ( const string &  path,
const string &  contents 
)
pure virtual

Create a file, with the specified name and contents Returns true on success, false on failure.

Implemented in VirtualFileSystem, and RealDiskInterface.

Referenced by Builder::StartEdge().


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