From 42c85126304f95c8f707bb7854a20b2e3d24e784 Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Wed, 4 Mar 2015 17:04:31 +0100 Subject: [PATCH] fix ReDirRandom: max value --- cunit/cuReTraverser.cpp | 8 ++++---- os/ReDirTools.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cunit/cuReTraverser.cpp b/cunit/cuReTraverser.cpp index 708f8ab..db5b713 100644 --- a/cunit/cuReTraverser.cpp +++ b/cunit/cuReTraverser.cpp @@ -128,15 +128,15 @@ private: } checkOneFile("x1.txt", "dir1_2_1", hashPath); checkOneFile("x2.txt", "dir1_2_1", hashPath); - bool changed1 = listChanged.find("x1.txt") != (size_t) -1; - bool changed2 = listChanged.find("x2.txt") != (size_t) -1; + bool changed1 = listChanged.find("x1.txt") != (ReSeqArray::Index) -1; + bool changed2 = listChanged.find("x2.txt") != (ReSeqArray::Index) -1; checkT(changed1 != changed2); checkOneFile("dir1_2_1", "dir1_2", hashPath); checkT(listChanged.find("dir1_2_1") >= 0); checkOneFile("dir1_1", "dir1", hashPath); checkOneFile("dir1_2", "dir1", hashPath); - changed1 = listChanged.find("dir1_1") != (size_t) -1; - changed2 = listChanged.find("dir1_2") != (size_t) -1; + changed1 = listChanged.find("dir1_1") != (ReSeqArray::Index) -1; + changed2 = listChanged.find("dir1_2") != (ReSeqArray::Index) -1; checkT(changed1 != changed2); checkF(hashPath.get("cache.txt", buffer)); } diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 7f45b22..1f451af 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -36,7 +36,7 @@ enum LOCATION_DIRTOOL { LC_COMPARE_DIR_1, // 50122 LC_DELETE_1, // 50123 }; -const char* ReDirTools::m_version = "2015.02.25"; +const char* ReDirTools::m_version = "2015.03.04"; ReLogger* ReDirTools::m_logger = NULL; static const char* s_helpSummary[] = { "dirtool or dt ", @@ -47,6 +47,7 @@ static const char* s_helpSummary[] = { "dirtool or dt ", "delete delete the selected files", "help shows info about the arguments/options", "list shows the meta data of the selected files", + "random displays random numbers", "statistic shows statistics about a direcctory tree", "synchronize copies only modified or new files from", " from a source directory tre to a target", @@ -105,6 +106,7 @@ const char* s_randomUsage[] = { const char* s_randomExamples[] = { "dirtool ra --multiple -w3 10 33", "dirtool rand -s 6 49", "dirtool rand --sort --width=1 5 50", + "dirtool rand --sort --width=1 2 10", NULL }; static const char* s_statisticUsage[] = @@ -1167,7 +1169,7 @@ void ReDirChecksum::buildStorage(const char* path, const char* storageFile){ digest2.update(line); fprintf(fp, "%s\n", line.str()); if (m_verboseLevel >= V_NORMAL) - fprintf(m_output, "%16s\t\%s", + fprintf(m_output, "%16s\t%s", entry->isDirectory() ? "" : m_digest->hexDigest().str(), entry->fullName()); } @@ -1465,7 +1467,7 @@ void ReDirDelete::processFile(ReDirStatus_t* entry) { if (m_verboseLevel >= V_NORMAL){ fprintf(m_output, "%s\n", name); } - if (unlink(name) != 0) + if (_unlink(name) != 0) m_logger->sayF(LOG_ERROR | CAT_FILE, LC_DELETE_1, i18n("cannot delete ($1): $2")).arg(errno).arg(name).end(); } @@ -1566,6 +1568,8 @@ void ReDirRandom::doIt() { from = atol(m_programArgs.getArg(2)); ReShiftRandom rand; rand.setSeed(rand.nearTrueRandom()); + for (int ii = rand.nextInt(100); ii > 0; ii--) + rand.nextInt(); int factor = to <= 1000 ? 1000 * 1000 : 1; int numbersPerLine = m_programArgs.getInt("perline"); int width = m_programArgs.getInt("width"); @@ -1579,8 +1583,7 @@ void ReDirRandom::doIt() { if (! multiple && count >= to - from + 1) help(i18n("not realy random: all possible values requested. Do you mean '--multiple'?")); while(found < count){ - value.setLength(0).appendInt(rand.nextInt(from * factor, to * factor) - / factor, "%010d"); + value.setLength(0).appendInt(from + rand.nextInt((to - from + 1) * factor) / factor, "%010d"); int ix = (int) values.find(value.str()); if (! multiple && ix != -1) continue; -- 2.39.5