Browse Source

Tested FileReference.


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@61 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 10 years ago
parent
commit
fcce81b431
2 changed files with 19 additions and 9 deletions
  1. 15
    8
      filesystem.cpp
  2. 4
    1
      filesystem.hpp

+ 15
- 8
filesystem.cpp View File

// Place, Suite 330, Boston, MA 02111-1307 USA // Place, Suite 330, Boston, MA 02111-1307 USA
//============================================================================== //==============================================================================
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstring>
#include <cerrno>
#include <stdexcept> #include <stdexcept>
#include "filesystem.hpp" #include "filesystem.hpp"
FileReference::FileReference(std::string fileName) : FileReference::FileReference(std::string fileName) :
name(fileName), name(fileName),
timestamp(0),
modTimestamp(0),
size_bytes(0), size_bytes(0),
fileExists(false), fileExists(false),
fileIsDirectory(false) { fileIsDirectory(false) {
char *realPath = realpath(name.c_str(), NULL); char *realPath = realpath(name.c_str(), NULL);
if (NULL == path) {
if (NULL == realPath) {
// Nothing to do if the file doesn't exist. // Nothing to do if the file doesn't exist.
if (ENOENT == errno) { if (ENOENT == errno) {
} }
// Something went wrong. // Something went wrong.
throw std::runtime_error("Error checking file \"" + name "\": " +
throw std::runtime_error("Error checking file \"" + name + "\": " +
getErrorText()); getErrorText());
} }
path = *realPath;
path.assign(realPath);
free(realPath); free(realPath);
} }
// Something went wrong. // Something went wrong.
throw std::runtime_error("Error updating status of file \"" + throw std::runtime_error("Error updating status of file \"" +
path "\": " + getErrorText());
path + "\": " + getErrorText());
} }
return modTimestamp; return modTimestamp;
} }
long FileReference::Size() const {
size_t FileReference::Size() const {
return size_bytes; return size_bytes;
} }
return path; return path;
} }
time_t FileReference::exists() const {
bool FileReference::exists() const {
return fileExists; return fileExists;
} }
time_t FileReference::isDirectory() const {
bool FileReference::isDirectory() const {
return fileIsDirectory; return fileIsDirectory;
} }

+ 4
- 1
filesystem.hpp View File

@returns the size of file when FileReference was created or @returns the size of file when FileReference was created or
last refreshed, or 0 if the file doesn't exist. last refreshed, or 0 if the file doesn't exist.
*/ */
long Size() const;
size_t Size() const;


/** Get full path. /** Get full path.


// //
static std::string getErrorText(); static std::string getErrorText();


/// Reset all members but the name and path. */
void reset();

/** Name provided to constructor. */ /** Name provided to constructor. */
std::string name; std::string name;



Loading…
Cancel
Save