-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchiver.cc
39 lines (35 loc) · 879 Bytes
/
archiver.cc
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
#include "tarstream.hh"
#include <iostream>
#include <string>
int main(int argc, char** argv)
{
if (argc != 2 && argc != 3)
{
std::cerr << "Usage: archiver input_directory [output_name]\n";
return 1;
}
TAR::Archiver archiver;
if (argc == 3)
{
std::string dest(argv[2]);
auto tar_extension = dest.find(".tar");
if (tar_extension == std::string::npos)
dest += ".tar";
if (archiver.archive(argv[1], dest) != TAR::Status::OK)
{
std::cerr << "Error: could not archive!\n";
return 1;
}
}
else
{
std::string dest(argv[1]);
dest += ".tar";
if (archiver.archive(argv[1], dest) != TAR::Status::OK)
{
std::cerr << "Error: could not archive!\n";
return 1;
}
}
return 0;
}