summaryrefslogtreecommitdiff
path: root/zen
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-02-07 00:18:30 +0000
committerB. Stack <bgstack15@gmail.com>2022-02-07 00:18:30 +0000
commit4cba562d787bfc92aeadbbc2ef199d4856523247 (patch)
tree374c62790fde0ce5514ef56750d0ff023d61b528 /zen
parentMerge branch 'b11.16' into 'master' (diff)
parent add upstream 11.17 (diff)
downloadFreeFileSync-11.17.tar.gz
FreeFileSync-11.17.tar.bz2
FreeFileSync-11.17.zip
Merge branch 'b11.17' into 'master'11.17
add upstream 11.17 See merge request opensource-tracking/FreeFileSync!41
Diffstat (limited to 'zen')
-rw-r--r--zen/format_unit.cpp26
-rw-r--r--zen/format_unit.h2
-rw-r--r--zen/http.cpp4
-rw-r--r--zen/open_ssl.cpp4
-rw-r--r--zen/perf.h2
-rw-r--r--zen/resolve_path.cpp16
-rw-r--r--zen/ring_buffer.h3
-rw-r--r--zen/stl_tools.h2
-rw-r--r--zen/symlink_target.h10
-rw-r--r--zen/sys_info.cpp2
10 files changed, 28 insertions, 43 deletions
diff --git a/zen/format_unit.cpp b/zen/format_unit.cpp
index d546124f..6803523a 100644
--- a/zen/format_unit.cpp
+++ b/zen/format_unit.cpp
@@ -90,14 +90,12 @@ std::wstring formatUnitTime(int val, UnitRemTime unit)
{
switch (unit)
{
- case UnitRemTime::sec:
- return _P("1 sec", "%x sec", val);
- case UnitRemTime::min:
- return _P("1 min", "%x min", val);
- case UnitRemTime::hour:
- return _P("1 hour", "%x hours", val);
- case UnitRemTime::day:
- return _P("1 day", "%x days", val);
+ //*INDENT-OFF*
+ case UnitRemTime::sec: return _P("1 sec", "%x sec", val);
+ case UnitRemTime::min: return _P("1 min", "%x min", val);
+ case UnitRemTime::hour: return _P("1 hour", "%x hours", val);
+ case UnitRemTime::day: return _P("1 day", "%x days", val);
+ //*INDENT-ON*
}
assert(false);
return _("Error");
@@ -152,15 +150,10 @@ std::wstring zen::formatRemainingTime(double timeInSec)
}
-//std::wstring zen::fractionToString1Dec(double fraction)
-//{
-// return printNumber<std::wstring>(L"%.1f", fraction * 100.0) + L'%'; //no need to internationalize fraction!?
-//}
-
-
-std::wstring zen::formatFraction(double fraction)
+std::wstring zen::formatPercent0(double fraction)
{
- return printNumber<std::wstring>(L"%.2f", fraction * 100.0) + L'%'; //no need to internationalize fraction!?
+ return numberTo<std::wstring>(std::lround(fraction * 100)) + L'%'; //need to localize percent!?
+ //return printNumber<std::wstring>(L"%.2f", fraction * 100) + L'%';
}
@@ -193,7 +186,6 @@ WeekDay impl::getFirstDayOfWeekImpl() //throw SysError
---------------------------------------
LC_TIME=en_DK.utf8 => Monday
LC_TIME=en_US.utf8 => Sunday */
-
const char* firstDay = ::nl_langinfo(_NL_TIME_FIRST_WEEKDAY); //[1-Sunday, 7-Saturday]
ASSERT_SYSERROR(firstDay && 1 <= *firstDay && *firstDay <= 7);
diff --git a/zen/format_unit.h b/zen/format_unit.h
index 4a839855..72a5e91b 100644
--- a/zen/format_unit.h
+++ b/zen/format_unit.h
@@ -17,7 +17,7 @@ namespace zen
const int bytesPerKilo = 1000;
std::wstring formatFilesizeShort(int64_t filesize);
std::wstring formatRemainingTime(double timeInSec);
-std::wstring formatFraction(double fraction); //within [0, 1]
+std::wstring formatPercent0(double fraction /*within [0, 1]*/); //zero decimal places
std::wstring formatUtcToLocalTime(time_t utcTime); //like Windows Explorer would...
std::wstring formatTwoDigitPrecision (double value); //format with fixed number of digits
diff --git a/zen/http.cpp b/zen/http.cpp
index fe3b8c4c..6ce6c324 100644
--- a/zen/http.cpp
+++ b/zen/http.cpp
@@ -12,7 +12,7 @@
using namespace zen;
-const std::chrono::seconds HTTP_ACCESS_TIME_OUT(20);
+constexpr std::chrono::seconds HTTP_ACCESS_TIME_OUT(20);
@@ -80,7 +80,7 @@ public:
if (postBuf)
{
extraOptions.emplace_back(CURLOPT_POSTFIELDS, postBuf->c_str());
- extraOptions.emplace_back(CURLOPT_POSTFIELDSIZE_LARGE, postBuf->size()); //postBuf not necessarily null-terminated!
+ extraOptions.emplace_back(CURLOPT_POSTFIELDSIZE_LARGE, postBuf->size()); //postBuf not necessarily null-terminated!
}
//carefully with these callbacks! First receive HTTP header without blocking,
diff --git a/zen/open_ssl.cpp b/zen/open_ssl.cpp
index 62560d78..5e4c370d 100644
--- a/zen/open_ssl.cpp
+++ b/zen/open_ssl.cpp
@@ -34,8 +34,8 @@ void zen::openSslInit()
//see apps_shutdown(): https://github.com/openssl/openssl/blob/master/apps/openssl.c
//see Curl_ossl_cleanup(): https://github.com/curl/curl/blob/master/lib/vtls/openssl.c
- assert(runningOnMainThread());
- //excplicitly init OpenSSL on main thread: seems to initialize atomically! But it still might help to avoid issues:
+ assert(runningOnMainThread());
+ //excplicitly init OpenSSL on main thread: seems to initialize atomically! But it still might help to avoid issues:
[[maybe_unused]] const int rv = ::OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT | OPENSSL_INIT_NO_LOAD_CONFIG, nullptr);
assert(rv == 1); //https://www.openssl.org/docs/man1.1.0/ssl/OPENSSL_init_ssl.html
}
diff --git a/zen/perf.h b/zen/perf.h
index 2ebf1955..76c98c85 100644
--- a/zen/perf.h
+++ b/zen/perf.h
@@ -80,7 +80,7 @@ public:
private:
bool paused_;
std::chrono::steady_clock::time_point startTime_ = std::chrono::steady_clock::now();
- std::chrono::nanoseconds elapsedUntilPause_{}; //std::chrono::duration is uninitialized by default! WTF! When will this stupidity end???
+ std::chrono::nanoseconds elapsedUntilPause_{}; //std::chrono::duration is uninitialized by default! WTF! When will this stupidity end!
};
diff --git a/zen/resolve_path.cpp b/zen/resolve_path.cpp
index 0a45646e..17d3b777 100644
--- a/zen/resolve_path.cpp
+++ b/zen/resolve_path.cpp
@@ -180,24 +180,14 @@ namespace
//expand volume name if possible, return original input otherwise
-Zstring expandVolumeName(Zstring pathPhrase) // [volname]:\folder [volname]\folder [volname]folder -> C:\folder
+Zstring expandVolumeName(Zstring pathPhrase) // [volname]:\folder [volname]\folder [volname]folder -> C:\folder
{
//we only expect the [.*] pattern at the beginning => do not touch dir names like "C:\somedir\[stuff]"
trim(pathPhrase, true, false);
+
if (startsWith(pathPhrase, Zstr('[')))
{
- const size_t posEnd = pathPhrase.find(Zstr(']'));
- if (posEnd != Zstring::npos)
- {
- Zstring volName = Zstring(pathPhrase.c_str() + 1, posEnd - 1);
- Zstring relPath = Zstring(pathPhrase.c_str() + posEnd + 1);
-
- if (startsWith(relPath, FILE_NAME_SEPARATOR))
- relPath = afterFirst(relPath, FILE_NAME_SEPARATOR, IfNotFoundReturn::none);
- else if (startsWith(relPath, Zstr(":\\"))) //Win-only
- relPath = afterFirst(relPath, Zstr('\\'), IfNotFoundReturn::none);
- return "/.../[" + volName + "]/" + relPath;
- }
+ return "/.../" + pathPhrase;
}
return pathPhrase;
}
diff --git a/zen/ring_buffer.h b/zen/ring_buffer.h
index ae2377d8..dfbb6493 100644
--- a/zen/ring_buffer.h
+++ b/zen/ring_buffer.h
@@ -182,6 +182,7 @@ public:
Iterator(Container& container, size_t offset) : container_(&container), offset_(offset) {}
Iterator& operator++() { ++offset_; return *this; }
+ Iterator& operator--() { --offset_; return *this; }
Iterator& operator+=(ptrdiff_t offset) { offset_ += offset; return *this; }
inline friend bool operator==(const Iterator& lhs, const Iterator& rhs) { assert(lhs.container_ == rhs.container_); return lhs.offset_ == rhs.offset_; }
inline friend ptrdiff_t operator-(const Iterator& lhs, const Iterator& rhs) { return lhs.offset_ - rhs.offset_; }
@@ -226,7 +227,7 @@ private:
static T* uninitializedMoveIfNoexcept(T* first, T* last, T* firstTrg, std::true_type ) { return std::uninitialized_move(first, last, firstTrg); }
static T* uninitializedMoveIfNoexcept(T* first, T* last, T* firstTrg, std::false_type) { return std::uninitialized_copy(first, last, firstTrg); } //throw ?
- void checkInvariants()
+ void checkInvariants() const
{
assert(bufStart_ == 0 || bufStart_ < capacity_);
assert(size_ <= capacity_);
diff --git a/zen/stl_tools.h b/zen/stl_tools.h
index e4cf2b5d..c2e8eff3 100644
--- a/zen/stl_tools.h
+++ b/zen/stl_tools.h
@@ -159,7 +159,7 @@ Iterator binarySearch(Iterator first, Iterator last, const T& value, CompLess le
{
static_assert(std::is_same_v<typename std::iterator_traits<Iterator>::iterator_category, std::random_access_iterator_tag>);
- first = std::lower_bound(first, last, value, less);
+ first = std::lower_bound(first, last, value, less); //alternative: std::partition_point
if (first != last && !less(value, *first))
return first;
else
diff --git a/zen/symlink_target.h b/zen/symlink_target.h
index 60353292..4f007047 100644
--- a/zen/symlink_target.h
+++ b/zen/symlink_target.h
@@ -43,16 +43,16 @@ namespace
zen::SymlinkRawContent getSymlinkRawContent_impl(const Zstring& linkPath) //throw FileError
{
using namespace zen;
- const size_t BUFFER_SIZE = 10000;
- std::vector<char> buffer(BUFFER_SIZE);
+ const size_t bufSize = 10000;
+ std::vector<char> buf(bufSize);
- const ssize_t bytesWritten = ::readlink(linkPath.c_str(), &buffer[0], BUFFER_SIZE);
+ const ssize_t bytesWritten = ::readlink(linkPath.c_str(), &buf[0], bufSize);
if (bytesWritten < 0)
THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot resolve symbolic link %x."), L"%x", fmtPath(linkPath)), "readlink");
- if (bytesWritten >= static_cast<ssize_t>(BUFFER_SIZE)) //detect truncation; not an error for readlink!
+ if (bytesWritten >= static_cast<ssize_t>(bufSize)) //detect truncation; not an error for readlink!
throw FileError(replaceCpy(_("Cannot resolve symbolic link %x."), L"%x", fmtPath(linkPath)), formatSystemError("readlink", L"", L"Buffer truncated."));
- return {Zstring(&buffer[0], bytesWritten)}; //readlink does not append 0-termination!
+ return {Zstring(&buf[0], bytesWritten)}; //readlink does not append 0-termination!
}
diff --git a/zen/sys_info.cpp b/zen/sys_info.cpp
index 54a5ecae..cc852510 100644
--- a/zen/sys_info.cpp
+++ b/zen/sys_info.cpp
@@ -185,6 +185,8 @@ Zstring getUserDir() //throw FileError
return "/root";
else
return "/home/" + loginUser;
+
+ //safer? sudo --user $userName sh -c 'echo $HOME'
}
}
bgstack15