2
* Copyright (c) 2002 Robert Collins.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* A copy of the GNU General Public License can be found at
12
* Written by Robert Collins <robertc@hotmail.com>
17
#include "FileSystemVisitor.h"
19
#include <sys/types.h>
20
#include <sys/unistd.h>
24
#include "Directory.h"
26
File::File (string const &path, bool const isASymlink, mode_t const &protection) : path_(path), symlink_(isASymlink), mode_(protection)
31
File::visit (FileSystemVisitor &aVisitor)
33
aVisitor.visitFile (*this);
36
/* XXX: todo: optional chmod on the copied file.
38
* do the Right Thing with Symlinks.
41
File::Copy (string const &source, string const& target)
43
if (Directory::Exists(source))
44
throw (string) "Source was a directory (" + source + ")";
45
ifstream ifs(source.c_str(), ios::in);
47
throw (string) "Can't open source file (" + source + ")";
49
fstream ofs (target.c_str(), ios::out | ios::trunc);
51
throw (string) "Can't open target file (" + target + ")";
53
/* string based copy */
55
while(getline(ifs, s))
57
if (!ifs.good() || !ofs.good())
58
throw (string) "File::Copy Failed during copy";