Skip to content

Commit

Permalink
fix some small problem in archiver, no change to libcsc
Browse files Browse the repository at this point in the history
  • Loading branch information
fusiyuan2010 committed Mar 25, 2015
1 parent 5a7b73d commit 9674c03
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/archiver/csa_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class InputFile {

bool open(const char* filename) {
in=fopen(filename, "rb");
if (!in) perror(filename);
return in!=0;
}

Expand Down Expand Up @@ -162,9 +161,6 @@ class InputFile {
std::wstring w=utow(filename, true);
in=CreateFile(w.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (in==INVALID_HANDLE_VALUE){
fprintf(stderr, "File open error %s\n", filename);
}
return in!=INVALID_HANDLE_VALUE;
}

Expand Down Expand Up @@ -231,7 +227,7 @@ class OutputFile {
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (out==INVALID_HANDLE_VALUE) {
fprintf(stderr, "File open error %s\n", filename);
fprintf(stderr, "File open error %s\n", filename.c_str());
DWORD x = GetLastError();
printf("%d", x);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/archiver/csa_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ int CompressionWorker::do_work()
{
FileReader file_reader;
file_reader.obj = new AsyncFileReader(task_->filelist,
std::min<uint32_t>(32 * 1048576, task_->total_size));
std::min<uint64_t>(32 * 1048576, task_->total_size));
file_reader.is.Read = file_read_proc;

FileWriter file_writer;
file_writer.obj = new AsyncArchiveWriter(*abs_, 8 * 1048576, arc_lock_);
file_writer.os.Write = file_write_proc;

CSCProps p;
CSCEncProps_Init(&p, std::min<uint32_t>(dict_size_, task_->total_size), level_);
CSCEncProps_Init(&p, std::min<uint64_t>(dict_size_, task_->total_size), level_);
CSCEncHandle h = CSCEnc_Create(&p, (ISeqOutStream*)&file_writer);
uint8_t buf[CSC_PROP_SIZE];
CSCEnc_WriteProperties(&p, buf, 0);
Expand Down
35 changes: 21 additions & 14 deletions src/archiver/csarc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CSArc {
void compress_index();
void decompress_index();
void compress_mt(vector<MainTask> &tasks);
void decompress_mt(vector<MainTask> &tasks);
int decompress_mt(vector<MainTask> &tasks);

public:
int Add();
Expand Down Expand Up @@ -407,7 +407,7 @@ void CSArc::compress_mt(vector<MainTask> &tasks)
pi.Finish();
}

void CSArc::decompress_mt(vector<MainTask> &tasks)
int CSArc::decompress_mt(vector<MainTask> &tasks)
{
DecompressionWorker *workers[8];
uint32_t workertasks[8];
Expand Down Expand Up @@ -467,14 +467,16 @@ void CSArc::decompress_mt(vector<MainTask> &tasks)

if (decomp_ret < 0) {
fprintf(stderr, "Extraction error, archive corrupted\n");
return -1;
}
return 0;
}

int CSArc::Add()
{
{
// check if file already exists
OutputFile f;
InputFile f;
f.open(arcname_.c_str());
if (f.isopen() && !overwrite_) {
fprintf(stderr, "Archive %s already exists, use -f to force overwrite\n", arcname_.c_str());
Expand Down Expand Up @@ -598,7 +600,7 @@ int CSArc::check_header()
int CSArc::Extract()
{
if (check_header() < 0)
return -1;
return 1;
decompress_index();

vector<MainTask> tasks;
Expand Down Expand Up @@ -644,8 +646,10 @@ int CSArc::Extract()
f.close(it->second.edate, it->second.eattr);
}
}
decompress_mt(tasks);
return 0;
if (decompress_mt(tasks) < 0)
return -1;
else
return 0;
}

int CSArc::List()
Expand Down Expand Up @@ -697,8 +701,10 @@ int CSArc::Test()
task->push_back(DUMMY_FILENAME, ff.posfile, ff.size, ff.posblock, ff.checksum, it);
}
}
decompress_mt(tasks);
return 0;
if (decompress_mt(tasks) < 0)
return -1;
else
return 0;
}

// Return the part of fn up to the last slash
Expand Down Expand Up @@ -829,7 +835,7 @@ bool CSArc::isselected(const char* filename) {
int main(int argc, char *argv[])
{
CSArc csarc;
fprintf(stderr, "CSArc 3.3, experimential archiver by Siyuan Fu\n (https://github.com/fusiyuan2010)\n");
fprintf(stderr, "CSArc 3.3, experimental archiver by Siyuan Fu\n (https://github.com/fusiyuan2010)\n");

if (argc < 3) {
fprintf(stderr, "At least two arguments, command and archive name\n");
Expand All @@ -844,26 +850,27 @@ int main(int argc, char *argv[])
return 1;
}

int ret = 0;
switch(op) {
case 'a':
csarc.Add();
ret = csarc.Add();
break;
case 't':
csarc.Test();
ret = csarc.Test();
break;
case 'l':
csarc.List();
ret = csarc.List();
break;
case 'x':
csarc.Extract();
ret = csarc.Extract();
break;
default:
csarc.Usage();
fprintf(stderr, "Invalid command '%c'\n", op);
return 1;
}

return 0;
return ret;
}


Expand Down

0 comments on commit 9674c03

Please sign in to comment.