Skip to content

Commit

Permalink
merge changes from poco-1.11.8
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Oct 16, 2023
1 parent 4770594 commit 62837ad
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 194 deletions.
4 changes: 4 additions & 0 deletions Foundation/include/Poco/TemporaryFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class Foundation_API TemporaryFile: public File
/// The class does, however, delete the temporary
/// file - either in the destructor, or immediately
/// before the application terminates.
///
/// Note: Due to the way the temporary file names are generated,
/// collisions may be possible after 400-500 Million
/// file names generated by a single process.
{
public:
TemporaryFile();
Expand Down
40 changes: 30 additions & 10 deletions Foundation/src/TemporaryFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "Poco/Process.h"
#endif
#include "Poco/Mutex.h"
#include "Poco/Random.h"
#include <algorithm>
#include <random>
#include <set>
#include <sstream>

Expand Down Expand Up @@ -132,19 +135,36 @@ void TemporaryFile::registerForDeletion(const std::string& path)
}


namespace
std::string TemporaryFile::tempName(const std::string& tempDir)
{
static constexpr int UNIQUE_LENGTH = 8;
static FastMutex mutex;
}
static unsigned long count = 0;
static Poco::Random random;
static std::string alphabet = "abcdefghijklmnopqrstuvwxyz";
static std::string randomChars;

unsigned long n;
{
Poco::FastMutex::ScopedLock lock(mutex);

if (count == 0)
{
random.seed();

std::random_device rd;
std::mt19937 mt(rd());
randomChars.reserve(alphabet.size() * UNIQUE_LENGTH);
for (int i = 0; i < UNIQUE_LENGTH; i++)
{
std::shuffle(alphabet.begin(), alphabet.end(), mt);
randomChars.append(alphabet);
}
}
n = (count += random.next(1000) + 1);
}

std::string TemporaryFile::tempName(const std::string& tempDir)
{
std::ostringstream name;
static unsigned long count = 0;
mutex.lock();
unsigned long n = count++;
mutex.unlock();
name << (tempDir.empty() ? Path::temp() : tempDir);
if (name.str().at(name.str().size() - 1) != Path::separator())
{
Expand All @@ -155,9 +175,9 @@ std::string TemporaryFile::tempName(const std::string& tempDir)
#else
name << "tmp" << Process::id();
#endif
for (int i = 0; i < 6; ++i)
for (int i = 0; i < UNIQUE_LENGTH; i++)
{
name << char('a' + (n % 26));
name << randomChars[alphabet.size()*i + (n % 26)];
n /= 26;
}
return name.str();
Expand Down
22 changes: 20 additions & 2 deletions Foundation/testsuite/src/FileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ void FileTest::testCopy()
f1.setWriteable().remove();
}


void FileTest::testCopyFailIfDestinationFileExists()
{
std::ofstream ostr("testfile.dat");
Expand Down Expand Up @@ -414,6 +415,7 @@ void FileTest::testMove()
assertTrue (f1 == f2);
}


void FileTest::testMoveFailIfDestinationFileExists() {
std::ofstream ostr("testfile.dat");
ostr << "Hello, world!" << std::endl;
Expand All @@ -430,6 +432,7 @@ void FileTest::testMoveFailIfDestinationFileExists() {
f1.setWriteable().remove();
}


void FileTest::testCopyDirectory()
{
Path pd1("testdir");
Expand Down Expand Up @@ -499,6 +502,7 @@ void FileTest::testCopyDirectory()
fd3.remove(true);
}


void FileTest::testCopyDirectoryFailIfExists()
{
Path pd1("testdir");
Expand Down Expand Up @@ -538,6 +542,7 @@ void FileTest::testCopyDirectoryFailIfExists()
fd2.remove(true);
}


void FileTest::testRename()
{
std::ofstream ostr("testfile.dat");
Expand All @@ -555,6 +560,7 @@ void FileTest::testRename()
f2.remove();
}


void FileTest::testRenameFailIfExists() {
std::ofstream ostr("testfile.dat");
ostr << "Hello, world!" << std::endl;
Expand All @@ -580,8 +586,6 @@ void FileTest::testRenameFailIfExists() {
}




void FileTest::testLongPath()
{
#if defined(_WIN32) && !defined(_WIN32_WCE)
Expand All @@ -606,6 +610,19 @@ void FileTest::testLongPath()
}


void FileTest::testTemporaryFile()
{
const int COUNT = 10000;
std::set<std::string> paths;
for (int i = 0; i < COUNT; i++)
{
Poco::TemporaryFile f;
paths.insert(f.path());
}
assertTrue (paths.size() == COUNT);
}


void FileTest::setUp()
{
File f("testfile.dat");
Expand Down Expand Up @@ -654,6 +671,7 @@ CppUnit::Test* FileTest::suite()
CppUnit_addTest(pSuite, FileTest, testRenameFailIfExists);
CppUnit_addTest(pSuite, FileTest, testRootDir);
CppUnit_addTest(pSuite, FileTest, testLongPath);
CppUnit_addTest(pSuite, FileTest, testTemporaryFile);

return pSuite;
}
1 change: 1 addition & 0 deletions Foundation/testsuite/src/FileTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class FileTest: public CppUnit::TestCase
void testRenameFailIfExists();
void testRootDir();
void testLongPath();
void testTemporaryFile();

void setUp();
void tearDown();
Expand Down
46 changes: 0 additions & 46 deletions NetSSL_Win/build.gradle

This file was deleted.

56 changes: 0 additions & 56 deletions NetSSL_Win/samples/build.gradle

This file was deleted.

70 changes: 0 additions & 70 deletions NetSSL_Win/testsuite/build.gradle

This file was deleted.

32 changes: 32 additions & 0 deletions Util/include/Poco/Util/AbstractConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,37 @@ class Util_API AbstractConfiguration: public Poco::RefCountedObject
/// Returns true iff events are enabled.

protected:
class ScopedLock
/// A helper class allowing to temporarily
/// lock an entire AbstractConfiguration,
/// for use by subclasses. A typical use
/// case is loading or saving an entire
/// configuration in a thread-safe way.
///
/// Caution: Thoughtless use of this class
/// may easily lead to deadlock situations
/// in connection with events if any of the
/// mutating methods (set...(), remove())
/// are called with the lock held. Therefore
/// this class is available to subclasses
/// only, not for general use.
{
public:
explicit ScopedLock(const AbstractConfiguration& c):
_c(c)
{
_c._mutex.lock();
}

~ScopedLock()
{
_c._mutex.unlock();
}

private:
const AbstractConfiguration& _c;
};

virtual bool getRaw(const std::string& key, std::string& value) const = 0;
/// If the property with the given key exists, stores the property's value
/// in value and returns true. Otherwise, returns false.
Expand Down Expand Up @@ -486,6 +517,7 @@ class Util_API AbstractConfiguration: public Poco::RefCountedObject
friend class LayeredConfiguration;
friend class ConfigurationView;
friend class ConfigurationMapper;
friend class ScopedLock;
};


Expand Down
1 change: 0 additions & 1 deletion Util/src/AbstractConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ std::string AbstractConfiguration::getRawString(const std::string& key) const

std::string AbstractConfiguration::getRawString(const std::string& key, const std::string& defaultValue) const
{

Mutex::ScopedLock lock(_mutex);

std::string value;
Expand Down
Loading

0 comments on commit 62837ad

Please sign in to comment.