Skip to content

Commit

Permalink
Merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
herve-er committed Oct 21, 2024
1 parent bfeff45 commit 3eba13d
Show file tree
Hide file tree
Showing 30 changed files with 482 additions and 239 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
./infomaniak-build-tools/run-tests.ps1
- name: Compute code coverage
if: false
run : |
rm -Force -ErrorAction SilentlyContinue BullseyeCoverageExclusions
echo "exclude folder 3rdparty/\nexclude folder ../" >> BullseyeCoverageExclusions
Expand All @@ -74,11 +75,13 @@ jobs:
& "covxml.exe" "-f" "$env:COVFILE" "-o" "coverage.xml"
- name: Install sonar-scanner
if: false
uses: SonarSource/sonarcloud-github-c-cpp@v3
env:
SONAR_HOST_URL: https://sonarcloud.io

- name: Run sonar-scanner
if: false
env:
GITHUB_TOKEN: ${{ github.token }}
SONAR_TOKEN: ${{ secrets.SONAR_DESKTOP_KDRIVE_TOKEN }}
Expand Down
54 changes: 28 additions & 26 deletions infomaniak-build-tools/translate_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import deepl
import errno
import os
from pathlib import Path
import re
import shutil
import subprocess
Expand Down Expand Up @@ -54,18 +55,23 @@ def version_regex(arg_value, pattern=re.compile(r'^(\d+\.)?(\d+\.)?(\*|\d+)')):
parser.add_argument('-d', '--date', metavar="", type=int, help='The planned release date (defaults to today)', default=datetime.date.today().strftime('%Y%m%d'))
args = parser.parse_args()

if not os.path.isfile(f"kDrive-template.html"):
sys.exit("Unable to find kDrive-template.html.");
if not os.path.isfile("kDrive-template.html"):
sys.exit("Unable to find 'kDrive-template.html'.")

fullName = f"kDrive-{args.version}.{args.date}"
dirPath = f"../release_notes/{fullName}"
dirPath = Path(__file__).parent.parent / "release_notes"

if not dirPath.exists():
sys.exit(f"Release notes path does not exist: '{dirPath}'. \nAborting.")

dirPath = dirPath / Path(fullName)

deepl_key = os.getenv("DEEPL_AUTH_KEY")
if not deepl_key:
sys.exit("error: The DeepL API key is not set in env");
sys.exit("error: The DeepL API key is not set in env")
translator = deepl.Translator(deepl_key)

target_lang = [
target_languages = [
'FR',
'DE',
'ES',
Expand All @@ -78,16 +84,15 @@ def version_regex(arg_value, pattern=re.compile(r'^(\d+\.)?(\d+\.)?(\*|\d+)')):
'macOS'
]

def split_os(lang):
lang_ext = f"-{lang.lower()}" if lang != 'en' else ""
def split_os(lang, fullName):
lang_ext = lang.lower()

for os_name in os_list:
os_ext = f"-{os_name.lower()}" if os_name != 'macOS' else ""
if os_name != 'macOS':
shutil.copyfile(f"{fullName}{lang_ext}.html", f"{fullName}{os_ext}{lang_ext}.html")
with open(f"{fullName}{os_ext}{lang_ext}.html", "r") as f:
os_ext = os_name.lower()
shutil.copyfile(f"{fullName}-{lang_ext}.html", f"{fullName}-{os_ext}-{lang_ext}.html")
with open(f"{fullName}-{os_ext}-{lang_ext}.html", "r") as f:
lines = f.readlines()
with open(f"{fullName}{os_ext}{lang_ext}.html", "w") as f:
with open(f"{fullName}-{os_ext}-{lang_ext}.html", "w") as f:
for line in lines:
if any(os_note in line for os_note in os_list):
if (f"<li>{os_name}" in line):
Expand All @@ -96,29 +101,26 @@ def split_os(lang):
f.write(line)

print(f"Generating Release Notes for kDrive-{args.version}.{args.date}")
Path(dirPath).mkdir(mode=0o755, exist_ok=True)

try:
os.mkdir(dirPath, mode = 0o755)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
pass

shutil.copyfile("kDrive-template.html", f"{dirPath}/{fullName}.html")
shutil.copyfile("kDrive-template.html", f"{dirPath}/{fullName}-en.html")
os.chdir(dirPath)

try:
for lang in target_lang:
for target_lang in target_languages:
print(f" - Notes for language {target_lang}")
translator.translate_document_from_filepath(
f"{fullName}.html",
f"{fullName}-{lang.lower()}.html",
target_lang=lang,
f"{fullName}-en.html",
f"{fullName}-{target_lang.lower()}.html",
target_lang=target_lang,
)
split_os(lang)
split_os(target_lang, fullName)
Path(f"{fullName}-{target_lang.lower()}.html").unlink()
except Exception as e:
print(e)

split_os('en')
split_os('en', fullName)
Path(f"{fullName}-en.html").unlink() # Remove english template

subprocess.run(['../../infomaniak-build-tools/encode.sh'], shell=True)

Expand Down
7 changes: 4 additions & 3 deletions src/libcommon/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ size_t CommonUtility::maxPathLength() {
// For folders in short path mode, it is MAX_PATH - 12
// (https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry)
// We decided to apply this rule for files too. We could else encounter issues.
// If the path length of a folder is > MAX_PATH - 12 and the path length of a file in this folder is between MAX_PATH - 12 and MAX_PATH.
// It would lead to a synced file in a folder that is not synced (hence excluded because of its path length).
// If the path length of a folder is > MAX_PATH - 12 and the path length of a file in this folder is between MAX_PATH - 12 and
// MAX_PATH. It would lead to a synced file in a folder that is not synced (hence excluded because of its path length).
return (_maxPathWin == MAX_PATH_LENGTH_WIN_LONG) ? MAX_PATH_LENGTH_WIN_LONG : MAX_PATH_LENGTH_WIN_SHORT - 12;
#elif defined(__APPLE__)
return MAX_PATH_LENGTH_MAC;
Expand Down Expand Up @@ -728,7 +728,8 @@ bool CommonUtility::isVersionLower(const std::string &currentVersion, const std:
return false; // Should not happen
}

return std::ranges::lexicographical_compare(currTabVersion, targetTabVersion);
return std::lexicographical_compare(currTabVersion.begin(), currTabVersion.end(), targetTabVersion.begin(),
targetTabVersion.end());
}

static std::string tmpDirName = "kdrive_" + CommonUtility::generateRandomStringAlphaNum();
Expand Down
21 changes: 17 additions & 4 deletions src/libsyncengine/db/syncdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2393,8 +2393,6 @@ bool SyncDb::reinstateEncodingOfLocalNames(const std::string &dbFromVersionNumbe

LOG_DEBUG(_logger, "Upgrade < 3.6.7 Sync DB");

normalizeRemoteNames();

Sync sync;
bool found = false;
ParmsDb::instance()->selectSync(_dbPath, sync, found);
Expand All @@ -2405,15 +2403,30 @@ bool SyncDb::reinstateEncodingOfLocalNames(const std::string &dbFromVersionNumbe

const SyncPath &localDrivePath = sync.localPath();

bool exists = false;
IoError existenceCheckError = IoError::Success;
if (!IoHelper::checkIfPathExists(localDrivePath, exists, existenceCheckError)) {
LOGW_WARN(_logger,
L"Error in IoHelper::checkIfPathExists" << Utility::formatIoError(localDrivePath, existenceCheckError));
return false;
}
if (!exists) {
LOGW_INFO(_logger, L"The synchronisation folder " << Utility::formatSyncPath(localDrivePath)
<< L" does not exist anymore. No Sync DB upgrade to do.");
return true;
}

if (!normalizeRemoteNames()) return false;

NamedNodeMap namedNodeMap;
if (!selectNamesWithDistinctEncodings(namedNodeMap)) return false;

IoHelper::DirectoryIterator dir;
IoError ioError = IoError::Success;
IoHelper::getDirectoryIterator(localDrivePath, true, ioError, dir);
if (ioError != IoError::Success) {
LOGW_WARN(_logger, L"Error in DirectoryIterator: " << Utility::formatIoError(localDrivePath, ioError).c_str());
return false;
LOGW_WARN(_logger, L"Error in DirectoryIterator: " << Utility::formatIoError(localDrivePath, ioError));
return (ioError == IoError::NoSuchFileOrDirectory) || (ioError == IoError::AccessDenied);
}

SyncNameMap localNames;
Expand Down
33 changes: 11 additions & 22 deletions src/libsyncengine/progress/progressinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

namespace KDC {

ProgressInfo::ProgressInfo(std::shared_ptr<SyncPal> syncPal) :
_syncPal(syncPal), _totalSizeOfCompletedJobs(0), _maxFilesPerSecond(0), _maxBytesPerSecond(0), _update(false) {
ProgressInfo::ProgressInfo(std::shared_ptr<SyncPal> syncPal) : _syncPal(syncPal) {
reset();
}

Expand Down Expand Up @@ -77,44 +76,43 @@ void ProgressInfo::updateEstimates() {
}

void ProgressInfo::initProgress(const SyncFileItem &item) {
SyncPath path = item.newPath().has_value() ? item.newPath().value() : item.path();
const SyncPath path = item.newPath().has_value() ? item.newPath().value() : item.path();
ProgressItem progressItem;
progressItem.setItem(item);
progressItem.progress().setTotal(item.size());
progressItem.progress().setCompleted(0);

_currentItems[path].push(progressItem);
_currentItems[Utility::normalizedSyncPath(path)].push(progressItem);

_fileProgress.setTotal(_fileProgress.total() + 1);
_sizeProgress.setTotal(_sizeProgress.total() + item.size());
}

bool ProgressInfo::getSyncFileItem(const SyncPath &path, SyncFileItem &item) {
auto it = _currentItems.find(path);
if (_currentItems.find(path) == _currentItems.end() || it->second.empty()) {
const auto it = _currentItems.find(Utility::normalizedSyncPath(path));
if (it == _currentItems.end() || it->second.empty()) {
return false;
}
item = it->second.front().item();
return true;
}

void ProgressInfo::setProgress(const SyncPath &path, int64_t completed) {
auto it = _currentItems.find(path);
void ProgressInfo::setProgress(const SyncPath &path, const int64_t completed) {
const auto it = _currentItems.find(Utility::normalizedSyncPath(path));
if (it == _currentItems.end() || it->second.empty()) {
return;
}

SyncFileItem &item = it->second.front().item();
if (!shouldCountProgress(item)) {
if (const SyncFileItem &item = it->second.front().item(); !shouldCountProgress(item)) {
return;
}

it->second.front().progress().setCompleted(completed);
recomputeCompletedSize();
}

void ProgressInfo::setProgressComplete(const SyncPath &path, SyncFileStatus status) {
auto it = _currentItems.find(path);
void ProgressInfo::setProgressComplete(const SyncPath &path, const SyncFileStatus status) {
const auto it = _currentItems.find(Utility::normalizedSyncPath(path));
if (it == _currentItems.end() || it->second.empty()) {
return;
}
Expand All @@ -135,7 +133,7 @@ void ProgressInfo::setProgressComplete(const SyncPath &path, SyncFileStatus stat

it->second.pop();
if (it->second.empty()) {
_currentItems.erase(path);
_currentItems.erase(Utility::normalizedSyncPath(path));
}
recomputeCompletedSize();
}
Expand Down Expand Up @@ -183,15 +181,6 @@ bool ProgressInfo::trustEta() const {
return totalProgress().estimatedEta() < 100 * optimisticEta();
}

Estimates ProgressInfo::fileProgress(const SyncFileItem &item) {
auto it = _currentItems.find(item.path());
if (it == _currentItems.end() || it->second.empty()) {
return Estimates();
}

return it->second.front().progress().estimates();
}

void ProgressInfo::recomputeCompletedSize() {
int64_t r = _totalSizeOfCompletedJobs;
for (auto &itemElt: _currentItems) {
Expand Down
33 changes: 16 additions & 17 deletions src/libsyncengine/progress/progressinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ class SyncPal;

class ProgressInfo {
public:
ProgressInfo(std::shared_ptr<SyncPal> syncPal);
explicit ProgressInfo(std::shared_ptr<SyncPal> syncPal);
~ProgressInfo();

void reset();
inline void setUpdate(bool value) { _update = value; }
inline bool update() const { return _update; }
void setUpdate(bool value) { _update = value; }
[[nodiscard]] bool update() const { return _update; }
void updateEstimates();
void initProgress(const SyncFileItem &item);
void setProgress(const SyncPath &path, int64_t completed);
void setProgressComplete(const SyncPath &path, SyncFileStatus status);
bool getSyncFileItem(const SyncPath &path, SyncFileItem &item);

inline int64_t totalFiles() const { return _fileProgress.total(); }
inline int64_t completedFiles() const { return _fileProgress.completed(); }
inline int64_t totalSize() const { return _sizeProgress.total(); }
inline int64_t completedSize() const { return _sizeProgress.completed(); }
inline int64_t currentFile() const { return completedFiles(); }
Estimates totalProgress() const;
[[nodiscard]] int64_t totalFiles() const { return _fileProgress.total(); }
[[nodiscard]] int64_t completedFiles() const { return _fileProgress.completed(); }
[[nodiscard]] int64_t totalSize() const { return _sizeProgress.total(); }
[[nodiscard]] int64_t completedSize() const { return _sizeProgress.completed(); }
[[nodiscard]] int64_t currentFile() const { return completedFiles(); }
[[nodiscard]] Estimates totalProgress() const;

private:
std::shared_ptr<SyncPal> _syncPal;
Expand All @@ -60,16 +60,15 @@ class ProgressInfo {
// DELETE a file and CREATE a directory with exact same name)
Progress _sizeProgress;
Progress _fileProgress;
int64_t _totalSizeOfCompletedJobs;
double _maxFilesPerSecond;
double _maxBytesPerSecond;
bool _update;
int64_t _totalSizeOfCompletedJobs{0};
double _maxFilesPerSecond{0.0};
double _maxBytesPerSecond{0.0};
bool _update{false};

int64_t optimisticEta() const;
bool trustEta() const;
Estimates fileProgress(const SyncFileItem &item);
[[nodiscard]] int64_t optimisticEta() const;
[[nodiscard]] bool trustEta() const;
void recomputeCompletedSize();
bool isSizeDependent(const SyncFileItem &item) const;
[[nodiscard]] bool isSizeDependent(const SyncFileItem &item) const;
};

} // namespace KDC
2 changes: 2 additions & 0 deletions src/libsyncengine/progress/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class SyncFileItem {

inline bool isDirectory() const { return _type == NodeType::Directory; }

bool operator==(const SyncFileItem &) const = default;

private:
NodeType _type{NodeType::Unknown};
SyncPath _path; // Sync folder relative filesystem path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@ bool ConflictResolverWorker::generateConflictedName(const std::shared_ptr<Node>
bool isOrphanNode /*= false*/) const {
SyncPath absoluteLocalFilePath = _syncPal->localPath() / node->getPath();
newName = PlatformInconsistencyCheckerUtility::instance()->generateNewValidName(
absoluteLocalFilePath, isOrphanNode ? PlatformInconsistencyCheckerUtility::SuffixTypeOrphan
: PlatformInconsistencyCheckerUtility::SuffixTypeConflict);
absoluteLocalFilePath, isOrphanNode ? PlatformInconsistencyCheckerUtility::SuffixType::Orphan
: PlatformInconsistencyCheckerUtility::SuffixType::Conflict);

// Check path size
size_t pathSize = absoluteLocalFilePath.parent_path().native().size() + 1 + newName.size();
if (PlatformInconsistencyCheckerUtility::instance()->checkPathLength(pathSize)) {
if (PlatformInconsistencyCheckerUtility::instance()->isPathTooLong(pathSize)) {
// Path is now too long, file needs to be moved to root directory
return false;
}
Expand Down
Loading

0 comments on commit 3eba13d

Please sign in to comment.