Skip to content

Commit 59b1cbf

Browse files
authored
Merge pull request #48 from KoslickiLab/fix-archive-path
Fix archive path (resolves #41)
2 parents 0c0cc70 + 59a493d commit 59b1cbf

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
# 8. Test correctness of tar.gz index
7070
- name: Test correctness of tar.gz index
7171
run: |
72-
./bin/index test/data/filelist_100.txt test/output/archived_index_100 -t 4 -n 1000 -s
72+
./bin/index test/data/filelist_100.txt test/output/archived_index_100 -t 4 -n 1000 -s -a test/output/archived_index_100.tar.gz
7373
rm -r test/output/archived_index_100
7474
bin/compare test/data/filelist_100.txt test/output/archived_index_100.tar.gz test/output/working_directory test/output/compare_100_v_100_tar -c 0.0 -t 2 -n 500 -k 51
7575
python test/compare_multisearch_results.py test/data/multisearch_100_v_100 test/output/compare_100_v_100_tar

src/MultiSketchIndex.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ bool MultiSketchIndex::write_to_file(std::string directory_name,
123123
int num_threads,
124124
std::vector<SketchInfo> info_of_sketches,
125125
bool store_archive,
126+
std::string archive_name,
126127
bool force_write) {
127128
// check if the directory exists, if not then create it
128129
struct stat info;
@@ -193,20 +194,22 @@ bool MultiSketchIndex::write_to_file(std::string directory_name,
193194
}
194195

195196
output_file.close();
197+
std::cout << "Index written to " << directory_name << std::endl;
196198

197-
if (store_archive) {
198-
std::cout << "Storing archive..." << std::endl;
199-
std::string archive_name = directory_name + ".tar.gz";
200-
std::string command = "tar -czf " + archive_name + " -C " + directory_name + " .";
201-
std::cout << command << std::endl;
202-
if (system(command.c_str()) != 0) {
203-
std::cout << "Error storing archive." << std::endl;
204-
return false;
205-
}
206-
std::cout << "Archive stored to " << archive_name << std::endl;
199+
if (!store_archive) {
200+
return true;
207201
}
208202

203+
std::cout << "Storing archive..." << std::endl;
204+
std::string command = "tar -czf " + archive_name + " -C " + directory_name + " .";
205+
std::cout << command << std::endl;
206+
if (system(command.c_str()) != 0) {
207+
std::cout << "Error storing archive." << std::endl;
208+
return false;
209+
}
210+
std::cout << "Archive stored to " << archive_name << std::endl;
209211
return true;
212+
210213
}
211214

212215

src/MultiSketchIndex.h

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class MultiSketchIndex {
136136
int num_threads,
137137
std::vector<SketchInfo> info_of_sketches,
138138
bool store_archive,
139+
std::string archive_name,
139140
bool force_write);
140141

141142
/**

src/index.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct Arguments {
1717
int number_of_threads;
1818
int num_hashtables;
1919
bool store_archive;
20+
string archive_name;
2021
bool force_write;
2122
};
2223

@@ -35,7 +36,7 @@ void parse_args(int argc, char** argv, Arguments &arguments) {
3536
.store_into(arguments.filelist_sketches);
3637

3738
parser.add_argument("index_directory_name")
38-
.help("The directory where the index will be stored (needs to be empty)")
39+
.help("The directory where the index will be stored (must be a directory)")
3940
.required()
4041
.store_into(arguments.index_directory_name);
4142

@@ -57,6 +58,11 @@ void parse_args(int argc, char** argv, Arguments &arguments) {
5758
.implicit_value(true)
5859
.store_into(arguments.store_archive);
5960

61+
parser.add_argument("-a", "--archive-name")
62+
.help("The name of the archive (will be discarded if store-archive is false)")
63+
.default_value("index.tar.gz")
64+
.store_into(arguments.archive_name);
65+
6066
parser.add_argument("-f", "--force-write")
6167
.help("Force write the index to the directory")
6268
.default_value(false)
@@ -83,6 +89,7 @@ void show_arguments(Arguments &arguments) {
8389
cout << "* number_of_threads: " << arguments.number_of_threads << endl;
8490
cout << "* num_hashtables: " << arguments.num_hashtables << endl;
8591
cout << "* store_archive: " << arguments.store_archive << endl;
92+
cout << "* archive_name: " << (arguments.store_archive ? arguments.archive_name : "N/A") << endl;
8693
cout << "* force_write: " << arguments.force_write << endl;
8794
cout << "* " << endl;
8895
cout << "*********************************" << endl;
@@ -115,8 +122,8 @@ int main(int argc, char** argv) {
115122
MultiSketchIndex multi_sketch_index(arguments.num_hashtables);
116123
compute_index_from_sketches(sketches, multi_sketch_index, arguments.number_of_threads);
117124
cout << "Index built." << endl;
118-
cout << "Some index stats:" << endl;
119-
multi_sketch_index.show_index_stats();
125+
//cout << "Some index stats:" << endl;
126+
//multi_sketch_index.show_index_stats();
120127

121128

122129
cout << "Writing index to file..." << endl;
@@ -129,6 +136,7 @@ int main(int argc, char** argv) {
129136
arguments.number_of_threads,
130137
info_of_sketches,
131138
arguments.store_archive,
139+
arguments.archive_name,
132140
arguments.force_write);
133141
if (!success) {
134142
cout << "Error writing index to file." << endl;

0 commit comments

Comments
 (0)