FS: Removed obsolete code

This commit is contained in:
Paul Beckingham 2016-02-06 12:19:01 -05:00
parent 205a3984d2
commit d798bbb106
2 changed files with 17 additions and 128 deletions

View file

@ -37,9 +37,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
#include <text.h>
#include <util.h>
#include <i18n.h>
#if defined SOLARIS || defined NETBSD || defined FREEBSD
@ -55,13 +53,6 @@
#define GLOB_BRACE 0
#endif
////////////////////////////////////////////////////////////////////////////////
std::ostream& operator<< (std::ostream& out, const Path& path)
{
out << path._data;
return out;
}
////////////////////////////////////////////////////////////////////////////////
Path::Path ()
{
@ -84,11 +75,6 @@ Path::Path (const std::string& in)
_data = expand (in);
}
////////////////////////////////////////////////////////////////////////////////
Path::~Path ()
{
}
////////////////////////////////////////////////////////////////////////////////
Path& Path::operator= (const Path& other)
{
@ -406,12 +392,6 @@ bool File::open ()
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool File::openAndLock ()
{
return open () && lock ();
}
////////////////////////////////////////////////////////////////////////////////
void File::close ()
{
@ -434,9 +414,7 @@ bool File::lock ()
if (_fh && _h != -1)
{
// l_type l_whence l_start l_len l_pid
struct flock fl {};
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
struct flock fl = {F_WRLCK, SEEK_SET, 0, 0, 0 };
fl.l_pid = getpid ();
if (fcntl (_h, F_SETLKW, &fl) == 0)
_locked = true;
@ -451,9 +429,7 @@ void File::unlock ()
if (_locked)
{
// l_type l_whence l_start l_len l_pid
struct flock fl {};
fl.l_type = F_UNLCK;
fl.l_whence = SEEK_SET;
struct flock fl = {F_UNLCK, SEEK_SET, 0, 0, 0 };
fl.l_pid = getpid ();
fcntl (_h, F_SETLK, &fl);
@ -498,31 +474,6 @@ void File::read (std::vector <std::string>& contents)
}
}
////////////////////////////////////////////////////////////////////////////////
// Opens if necessary.
void File::write (const std::string& line)
{
if (!_fh)
open ();
if (_fh)
fputs (line.c_str (), _fh);
}
////////////////////////////////////////////////////////////////////////////////
// Opens if necessary.
void File::write (const std::vector <std::string>& lines)
{
if (!_fh)
open ();
if (_fh)
{
for (auto& line : lines)
fputs (line.c_str (), _fh);
}
}
////////////////////////////////////////////////////////////////////////////////
// Opens if necessary.
void File::append (const std::string& line)
@ -548,7 +499,19 @@ void File::append (const std::vector <std::string>& lines)
{
fseek (_fh, 0, SEEK_END);
for (auto& line : lines)
fputs ((line + "\n").c_str (), _fh);
fputs (line.c_str (), _fh);
}
}
////////////////////////////////////////////////////////////////////////////////
void File::write_raw (const std::string& line)
{
if (!_fh)
open ();
if (_fh)
{
fputs (line.c_str (), _fh);
}
}
@ -559,7 +522,7 @@ void File::truncate ()
open ();
if (_fh)
ftruncate (_h, 0);
(void) ftruncate (_h, 0);
}
////////////////////////////////////////////////////////////////////////////////
@ -646,25 +609,6 @@ bool File::create (const std::string& name, int mode /* = 0640 */)
return false;
}
////////////////////////////////////////////////////////////////////////////////
std::string File::read (const std::string& name)
{
std::string contents = "";
std::ifstream in (name.c_str ());
if (in.good ())
{
std::string line;
line.reserve (1024);
while (getline (in, line))
contents += line + "\n";
in.close ();
}
return contents;
}
////////////////////////////////////////////////////////////////////////////////
bool File::read (const std::string& name, std::string& contents)
{
@ -745,46 +689,6 @@ bool File::write (
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool File::append (const std::string& name, const std::string& contents)
{
std::ofstream out (expand (name).c_str (),
std::ios_base::out | std::ios_base::app);
if (out.good ())
{
out << contents;
out.close ();
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool File::append (
const std::string& name,
const std::vector <std::string>& lines,
bool addNewlines /* = true */)
{
std::ofstream out (expand (name).c_str (),
std::ios_base::out | std::ios_base::app);
if (out.good ())
{
for (auto& line : lines)
{
out << line;
if (addNewlines)
out << "\n";
}
out.close ();
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool File::remove (const std::string& name)
{
@ -820,11 +724,6 @@ Directory::Directory (const std::string& in)
{
}
////////////////////////////////////////////////////////////////////////////////
Directory::~Directory ()
{
}
////////////////////////////////////////////////////////////////////////////////
Directory& Directory::operator= (const Directory& other)
{

View file

@ -38,7 +38,6 @@ public:
Path ();
Path (const Path&);
Path (const std::string&);
virtual ~Path ();
Path& operator= (const Path&);
bool operator== (const Path&);
@ -81,7 +80,6 @@ public:
virtual bool remove () const;
bool open ();
bool openAndLock ();
void close ();
bool lock ();
@ -90,11 +88,9 @@ public:
void read (std::string&);
void read (std::vector <std::string>&);
void write (const std::string&);
void write (const std::vector <std::string>&);
void append (const std::string&);
void append (const std::vector <std::string>&);
void write_raw (const std::string&);
void truncate ();
@ -105,13 +101,10 @@ public:
virtual time_t btime () const;
static bool create (const std::string&, int mode = 0640);
static std::string read (const std::string&);
static bool read (const std::string&, std::string&);
static bool read (const std::string&, std::vector <std::string>&);
static bool write (const std::string&, const std::string&);
static bool write (const std::string&, const std::vector <std::string>&, bool addNewlines = true);
static bool append (const std::string&, const std::string&);
static bool append (const std::string&, const std::vector <std::string>&, bool addNewlines = true);
static bool remove (const std::string&);
private:
@ -128,7 +121,6 @@ public:
Directory (const File&);
Directory (const Path&);
Directory (const std::string&);
virtual ~Directory ();
Directory& operator= (const Directory&);
@ -147,8 +139,6 @@ private:
bool remove_directory (const std::string&) const;
};
std::ostream& operator<< (std::ostream&, const Path&);
#endif
////////////////////////////////////////////////////////////////////////////////