Skip to content

feat(cli): support multiple folders to sync with --include file - #10574

Open
Arne-Zillhardt wants to merge 1 commit into
nextcloud:masterfrom
Arne-Zillhardt:feature/4780
Open

feat(cli): support multiple folders to sync with --include file#10574
Arne-Zillhardt wants to merge 1 commit into
nextcloud:masterfrom
Arne-Zillhardt:feature/4780

Conversation

@Arne-Zillhardt

Copy link
Copy Markdown

Resolves

#4780

Summary

Added the new --include flag that reads a file with the format <local path> <remote path> and syncs these folders with nextcloud.
I'm not really confident or sure about the implementation. I don't know if it's a good idea to just recreate the SyncEngine and iterate over the list of directorys (maybe also replace ~ with the user home?). I think the best and cleanest solution would be to give SyncEngine not only a list of files to exclude, but also to include, that it doesn't need to be recreated every time. But I'm not really sure how big of a change that would be or if it is even worth it.
So this is the proposal for a solution to the issue :)

TODO

  • Add Documentation

Checklist

AI (if applicable)

@mgallien mgallien left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the delay @Arne-Zillhardt
seems like we should get some new automated tests to ensure lack of regressions
I did not test your changes but they seem to me like the correct way to solve your use case

can you include automated tests that would use the simple way (without --include) and the new way of operating the command line client ?

maybe you could do them in a similar way to https://github.com/nextcloud/desktop/blob/master/test/testnextcloudcmdprovisioning.cpp

Comment thread src/cmd/cmd.cpp
options->source_dir = fi.absoluteFilePath();
}
options->source_dir = fi.absoluteFilePath();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove the extra while line ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I remove all extra white lines now? I had to rebase on master because of other changes in src/cmd/cmd.cpp (I think you also made them xD). I hope I merged them correcty.
I also (more or less) copied from the provisioning test and added a test for the --include flag. I hope the test cases are the right ones

Comment thread src/cmd/cmd.cpp Outdated
Comment on lines +264 to +271
} else if (option == "--include" && !it.peekNext().startsWith("-")) {
options->include = it.next();
QFileInfo fi(options->include);
if (!fi.exists()) {
std::cerr << "Include file '" << qPrintable(options->include) << "' does not exist." << std::endl;
exit(1);
}
options->include = fi.absoluteFilePath();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for simplicity, I would enforce the use of a single occurrence of the new option --include
so can you test that options->include is empty and if not return an error and do not proceed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't exactly know what you mean, but now --include only gets checked before if it is included, before parsing the file

Comment thread src/cmd/cmd.cpp
Comment on lines +419 to +455
QMap<QString, QString> foldersToSync;
if (!options.source_dir.isEmpty()) {
foldersToSync.insert(options.source_dir, options.remotePath);
} else {
QFile file(options.include);
if (!file.open(QIODevice::ReadOnly)) {
std::cerr << "Include file '" << qPrintable(file.fileName()) << "' could not be opened" << std::endl;
exit(1);
}

while (!file.atEnd()) {
QByteArray line = file.readLine().trimmed();

if (line.isEmpty() || line.startsWith('#')) {
continue;
}

QStringList splitEntry = QString::fromUtf8(line).split(u' ');
if (splitEntry.count() != 2) {
std::cerr << "Entry '" << qPrintable(QString::fromUtf8(line)) << "' is not in format '<local path> <remote path>'" <<std::endl;
exit(1);
}

QString localPath = splitEntry.at(0);
if (localPath.endsWith('/')) {
localPath.append('/');
}

QFileInfo fi(localPath);
if (!fi.exists()) {
std::cerr << "Included dir '" << qPrintable(localPath) << "' does not exist." << std::endl;
exit(1);
}

foldersToSync.insert(fi.absoluteFilePath(), splitEntry.at(1));
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you spit that into an utility function doing the parsing ?
in addition, we aim to use auto almost everywhere
can you try using it more ?
for example:
const auto splitEntry = QString::fromUtf8(line).split(u' ');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a utility function parseIncludeFile and hopefully used auto in my changes :)

Signed-off-by: Arne-Zillhartd <arne-zillhardt@noreply.codeberg.org>
@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants