Repository navigation
Expand file tree
/
Copy pathTmpFiles.cc
More file actions
77 lines (60 loc) · 1.29 KB
/
Copy pathTmpFiles.cc
File metadata and controls
77 lines (60 loc) · 1.29 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* TmpFiles.cc
*
* Collect and clean-up temporary files
*
* implemented by WangLu
* split off by Filodej <philodej@gmail.com>
*/
#include <iostream>
#include <cstdio>
#include <sys/stat.h>
#include <unistd.h>
#include "TmpFiles.h"
#include "Param.h"
#ifdef __MINGW32__
#include "util/mingw.h"
#endif
using namespace std;
namespace pdf2htmlEX {
TmpFiles::TmpFiles( const Param& param )
: param( param )
{ }
TmpFiles::~TmpFiles()
{
clean();
}
void TmpFiles::add( const string & fn)
{
if(!param.clean_tmp)
return;
if(tmp_files.insert(fn).second && param.debug)
cerr << "Add new temporary file: " << fn << endl;
}
// Return the total size of the temporary files in bytes
double TmpFiles::get_total_size() const
{
double total_size = 0;
struct stat st;
for(auto & fn : tmp_files)
{
stat(fn.c_str(), &st);
total_size += st.st_size;
}
return total_size;
}
void TmpFiles::clean()
{
if(!param.clean_tmp)
return;
for(auto & fn : tmp_files)
{
remove(fn.c_str());
if(param.debug)
cerr << "Remove temporary file: " << fn << endl;
}
rmdir(param.tmp_dir.c_str());
if(param.debug)
cerr << "Remove temporary directory: " << param.tmp_dir << endl;
}
} // namespace pdf2htmlEX