-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (45 loc) · 1.63 KB
/
Copy pathmain.cpp
File metadata and controls
56 lines (45 loc) · 1.63 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
//
// main.cpp
//
#include <string.h> // strcpy()
#include <limits.h> // PATH_MAX
#include <libgen.h> // dirname()
#include <iostream> // std::cout
#include "dirCopy.h"
#define ERRORMSG(msg) std::cout << "[ERROR] " << __func__ << ": " << msg << std::endl;
#define OUTMSG(msg) std::cout << msg << std::endl;
int main(int argc, const char* argv[])
{
if(argc < 3)
{
std::cout << "Usage: copy <source> <destination> <read_block_size (optional)>" << std::endl;
return 0;
}
const char* srcName = argv[1];
const char* dstName = argv[2];
size_t sparseBlockSize = (argc > 3 ? atoi(argv[3]) : 0);
// For simplicity, make sure that destination directory is not a sub-directory of source directory
char buf[PATH_MAX + 1] {};
strcpy(buf, dstName);
std::string destDirName = dirname(buf);
// std::cout << "destDir=" << destDir << "-->destDirName=" << destDirName << std::endl;
if(destDirName == srcName)
{
ERRORMSG("Cannot copy the source directory/file into itself");
return 1;
}
// Make destination directory based on source directory name
strcpy(buf, srcName);
std::string destDir = std::string(dstName) + "/" + basename(buf);
OUTMSG("Copy from :" << srcName);
OUTMSG("Copy to: " << destDir);
OUTMSG("Sparse files read block size: " << sparseBlockSize);
// Copy source directory into destination directory
DirCopy dirCopy(12); // Use 12 threads
if(!dirCopy.Copy(srcName, destDir, sparseBlockSize))
{
ERRORMSG("srcName=" << srcName << ", error '" << dirCopy.GetError() << "'");
return 1;
}
return 0;
}