Skip to content

Commit

Permalink
Merge pull request #503 from openzim/502-filename-extension-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Feb 24, 2021
2 parents 1ed3b93 + e705b41 commit 35cd997
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
14 changes: 6 additions & 8 deletions src/writer/creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ namespace zim
::close(data->out_fd);

TINFO("rename tmpfile to final one.");
DEFAULTFS::rename(data->basename+".zim.tmp", data->basename+".zim");
DEFAULTFS::rename(data->tmpFileName, data->zimName);

TINFO("finish");
}
Expand Down Expand Up @@ -404,22 +404,20 @@ namespace zim
nbClusters(0),
nbCompClusters(0),
nbUnCompClusters(0),
start_time(time(NULL))
start_time(time(NULL)),
zimName(fname),
tmpFileName(fname + ".tmp")
{
basename = (fname.size() > 4 && fname.compare(fname.size() - 4, 4, ".zim") == 0)
? fname.substr(0, fname.size() - 4)
: fname;
auto zim_name = basename + ".zim.tmp";
#ifdef _WIN32
int mode = _S_IREAD | _S_IWRITE;
#else
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
#endif
out_fd = open(zim_name.c_str(), O_RDWR|O_CREAT|O_TRUNC, mode);
out_fd = open(tmpFileName.c_str(), O_RDWR|O_CREAT|O_TRUNC, mode);
if (out_fd == -1){
perror(nullptr);
std::ostringstream ss;
ss << "Cannot create file " << zim_name;
ss << "Cannot create file " << tmpFileName;
throw std::runtime_error(ss.str());
}
if(lseek(out_fd, CLUSTER_BASE_OFFSET, SEEK_SET) != CLUSTER_BASE_OFFSET) {
Expand Down
3 changes: 2 additions & 1 deletion src/writer/creatordata.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ namespace zim
ThreadList workerThreads;
std::thread writerThread;
const CompressionType compression;
std::string basename;
std::string zimName;
std::string tmpFileName;
bool isEmpty = true;
bool isExtended = false;
zsize_t clustersSize;
Expand Down
4 changes: 2 additions & 2 deletions src/writer/xapianHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using namespace zim::writer;

FullTextXapianHandler::FullTextXapianHandler(CreatorData* data)
: mp_indexer(new XapianIndexer(data->basename+"_fulltext.idx", data->indexingLanguage, IndexingMode::FULL, true)),
: mp_indexer(new XapianIndexer(data->zimName+"_fulltext.idx", data->indexingLanguage, IndexingMode::FULL, true)),
mp_creatorData(data)
{}

Expand Down Expand Up @@ -71,7 +71,7 @@ void FullTextXapianHandler::handle(Dirent* dirent, std::shared_ptr<Item> item)
}

TitleXapianHandler::TitleXapianHandler(CreatorData* data)
: mp_indexer(new XapianIndexer(data->basename+"_title.idx", data->indexingLanguage, IndexingMode::TITLE, true)),
: mp_indexer(new XapianIndexer(data->zimName+"_title.idx", data->indexingLanguage, IndexingMode::TITLE, true)),
mp_creatorData(data)
{}

Expand Down
4 changes: 2 additions & 2 deletions test/creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void test_redirect_dirent(
TEST(ZimCreator, createEmptyZim)
{
unittests::TempFile temp("emptyzimfile");
auto tempPath = temp.path() + ".zim";
auto tempPath = temp.path();
writer::Creator creator;
creator.startZimCreation(tempPath);
creator.finishZimCreation();
Expand Down Expand Up @@ -171,7 +171,7 @@ class TestItem : public writer::Item
TEST(ZimCreator, createZim)
{
unittests::TempFile temp("zimfile");
auto tempPath = temp.path() + ".zim";
auto tempPath = temp.path();
writer::Creator creator;
creator.configIndexing(true, "eng");
creator.startZimCreation(tempPath);
Expand Down

0 comments on commit 35cd997

Please sign in to comment.