[go: up one dir, main page]

Menu

[r189]: / tags / 0.10 / lib / porg / file.cc  Maximize  Restore  History

Download this file

63 lines (50 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//=======================================================================
// file.cc
//-----------------------------------------------------------------------
// This file is part of the package porg
// Copyright (C) 2015 David Ricart
// For more information visit http://porg.sourceforge.net
//=======================================================================
#include "config.h"
#include "file.h"
using std::string;
using namespace Porg;
//
// Ctor. for newly logged files
//
File::File(string const& name_)
:
m_name(name_),
m_size(0),
m_inode(0),
m_ln_name()
{
struct stat s;
if (lstat(m_name.c_str(), &s) < 0)
return;
else if (S_ISLNK(s.st_mode)) {
char ln[4096];
int cnt = readlink(m_name.c_str(), ln, sizeof(ln) - 1);
if (cnt > 0) {
ln[cnt] = 0;
m_ln_name = ln;
}
}
m_inode = s.st_ino;
m_size = s.st_size;
}
//
// Ctor. for files read from database
//
File::File(string const& name_, ulong size_, string const& ln_name_ /* = "" */)
:
m_name(name_),
m_size(size_),
m_inode(0),
m_ln_name(ln_name_)
{ }
bool File::is_missing() const
{
struct stat s;
return lstat(m_name.c_str(), &s);
}