Merge lp:~charlesk/keeper/keeper-tar-create-require-zero-delimited-files into lp:keeper

Proposed by Charles Kerr
Status: Merged
Merge reported by: Charles Kerr
Merged at revision: not available
Proposed branch: lp:~charlesk/keeper/keeper-tar-create-require-zero-delimited-files
Merge into: lp:keeper
Prerequisite: lp:~charlesk/keeper/keeper-tar-create-handle-libarchive-failure-gracefully
Diff against target: 138 lines (+13/-43)
5 files modified
src/tar/main.cpp (+9/-39)
tests/fakes/helper-test.sh.in (+1/-1)
tests/unit/tar/ktc-invoke-nobus.sh.in (+1/-1)
tests/unit/tar/ktc-invoke-nofiles.sh.in (+1/-1)
tests/unit/tar/ktc-invoke.sh.in (+1/-1)
To merge this branch: bzr merge lp:~charlesk/keeper/keeper-tar-create-require-zero-delimited-files
Reviewer Review Type Date Requested Status
Xavi Garcia (community) Approve
Review via email: mp+301946@code.launchpad.net

Commit message

Remove the '-0' option from keeper-tar-create because it should be required, not optional.

Description of the change

An easy review this time: remove the '-0' option from keeper-tar-create because it should be required, not optional.

This also lets us remove the shell globbing code from keeper-tar-create as it's no longer needed.

To post a comment you must log in.
79. By Charles Kerr

in keeper-tar-create's usage string, fix typo

Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

Looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/tar/main.cpp'
--- src/tar/main.cpp 2016-08-03 18:58:12 +0000
+++ src/tar/main.cpp 2016-08-03 18:58:12 +0000
@@ -30,8 +30,6 @@
30#include <QFile>30#include <QFile>
31#include <QLocalSocket>31#include <QLocalSocket>
3232
33#include <glib.h>
34
35#include <sys/select.h>33#include <sys/select.h>
36#include <unistd.h>34#include <unistd.h>
3735
@@ -44,7 +42,7 @@
44{42{
4543
46QStringList44QStringList
47get_filenames_from_file(FILE * fp, bool zero)45get_filenames_from_file(FILE * fp)
48{46{
49 // don't wait forever...47 // don't wait forever...
50 int fd = fileno(fp);48 int fd = fileno(fp);
@@ -65,29 +63,9 @@
65 auto filenames_raw = file.readAll();63 auto filenames_raw = file.readAll();
66 file.close();64 file.close();
6765
68 QList<QByteArray> tokens;
69 if (zero)
70 {
71 tokens = filenames_raw.split('\0');
72 }
73 else
74 {
75 // can't find a Qt equivalent of g_shell_parse_argv()...
76 gchar** filenames_strv {};
77 GError* err {};
78 filenames_raw = QString(filenames_raw).toUtf8(); // ensure a trailing '\0'
79 g_shell_parse_argv(filenames_raw.constData(), nullptr, &filenames_strv, &err);
80 if (err != nullptr)
81 g_warning("Unable to parse file list: %s", err->message);
82 for(int i=0; filenames_strv && filenames_strv[i]; ++i)
83 tokens.append(QByteArray(filenames_strv[i]));
84 g_clear_pointer(&filenames_strv, g_strfreev);
85 g_clear_error(&err);
86 }
87
88 // massage into a QStringList66 // massage into a QStringList
89 QStringList filenames;67 QStringList filenames;
90 for (const auto& token : tokens)68 for (const auto& token : filenames_raw.split('\0'))
91 if (!token.isEmpty())69 if (!token.isEmpty())
92 filenames.append(QString::fromUtf8(token));70 filenames.append(QString::fromUtf8(token));
9371
@@ -102,28 +80,21 @@
102 parser.addHelpOption();80 parser.addHelpOption();
103 parser.setApplicationDescription(81 parser.setApplicationDescription(
104 "\n"82 "\n"
105 "Reads filenames from the standard input, delimited either by blanks (which can\n"83 "Reads filenames from the standard input, delimited either by a null character,\n"
106 "be protected with double or single quotes or a backslash), builds an in-memory\n"84 "builds an in-memory archive of those files, and sends them to the Keeper service\n"
107 "archive of those files, and sends them to the Keeper service to store remotely.\n"85 " to store remotely.\n"
108 "\n"86 "\n"
109 "Because Unix filenames can contain blanks and newlines, it is generally better\n"87 "You will need to insure that the program which produces input uses a null character\n"
110 "to use the -0 option, which prevents such problems. When using this option you\n"88 "as a separator. If that program is GNU find, for example, the -print0 option does\n"
111 "will need to ensure the program which produces input also uses a null character\n"
112 "a separator. If that program is GNU find, for example, the -print0 option does\n"
113 "this for you.\n"89 "this for you.\n"
114 "\n"90 "\n"
115 "Helper usage: find /your/data/path -print0 | " APP_NAME " -0 -a /bus/path"91 "Helper usage: find /your/data/path -print0 | " APP_NAME " -a /bus/path"
116 );92 );
117 QCommandLineOption compress_option{93 QCommandLineOption compress_option{
118 QStringList() << "c" << "compress",94 QStringList() << "c" << "compress",
119 QStringLiteral("Compress files before adding to archive")95 QStringLiteral("Compress files before adding to archive")
120 };96 };
121 parser.addOption(compress_option);97 parser.addOption(compress_option);
122 QCommandLineOption zero_delimiter_option{
123 QStringList() << "0" << "null",
124 QStringLiteral("Input items are terminated by a null character instead of by whitespace")
125 };
126 parser.addOption(zero_delimiter_option);
127 QCommandLineOption bus_path_option{98 QCommandLineOption bus_path_option{
128 QStringList() << "a" << "bus-path",99 QStringList() << "a" << "bus-path",
129 QStringLiteral("Keeper service's DBus path"),100 QStringLiteral("Keeper service's DBus path"),
@@ -132,7 +103,6 @@
132 parser.addOption(bus_path_option);103 parser.addOption(bus_path_option);
133 parser.process(app);104 parser.process(app);
134 const bool compress = parser.isSet(compress_option);105 const bool compress = parser.isSet(compress_option);
135 const bool zero = parser.isSet(zero_delimiter_option);
136 const auto bus_path = parser.value(bus_path_option);106 const auto bus_path = parser.value(bus_path_option);
137107
138 // gotta have the bus path108 // gotta have the bus path
@@ -142,7 +112,7 @@
142 }112 }
143113
144 // gotta have files114 // gotta have files
145 const auto filenames = get_filenames_from_file(stdin, zero);115 const auto filenames = get_filenames_from_file(stdin);
146 for (const auto& filename : filenames)116 for (const auto& filename : filenames)
147 qDebug() << "filename: " << filename;117 qDebug() << "filename: " << filename;
148 if (filenames.empty()) {118 if (filenames.empty()) {
149119
=== modified file 'tests/fakes/helper-test.sh.in'
--- tests/fakes/helper-test.sh.in 2016-07-29 14:20:23 +0000
+++ tests/fakes/helper-test.sh.in 2016-08-03 18:58:12 +0000
@@ -19,5 +19,5 @@
19#19#
2020
21echo $PWD >> /tmp/helper-pwd21echo $PWD >> /tmp/helper-pwd
22find ./ -type f -print0 | @KEEPER_TAR_CREATE_BIN@ -0 -a /com/canonical/keeper/helper22find ./ -type f -print0 | @KEEPER_TAR_CREATE_BIN@ -a /com/canonical/keeper/helper
23touch /tmp/simple-helper-finished23touch /tmp/simple-helper-finished
2424
=== modified file 'tests/unit/tar/ktc-invoke-nobus.sh.in'
--- tests/unit/tar/ktc-invoke-nobus.sh.in 2016-08-03 18:58:12 +0000
+++ tests/unit/tar/ktc-invoke-nobus.sh.in 2016-08-03 18:58:12 +0000
@@ -1,2 +1,2 @@
1find ./ -type f1find ./ -type f
2find ./ -type f -print0 | @KEEPER_TAR_CREATE_BIN@ -02find ./ -type f -print0 | @KEEPER_TAR_CREATE_BIN@
33
=== modified file 'tests/unit/tar/ktc-invoke-nofiles.sh.in'
--- tests/unit/tar/ktc-invoke-nofiles.sh.in 2016-08-03 18:58:12 +0000
+++ tests/unit/tar/ktc-invoke-nofiles.sh.in 2016-08-03 18:58:12 +0000
@@ -1,1 +1,1 @@
1@KEEPER_TAR_CREATE_BIN@ -0 -a /com/canonical/keeper/helper1@KEEPER_TAR_CREATE_BIN@ -a /com/canonical/keeper/helper
22
=== modified file 'tests/unit/tar/ktc-invoke.sh.in'
--- tests/unit/tar/ktc-invoke.sh.in 2016-07-22 13:49:34 +0000
+++ tests/unit/tar/ktc-invoke.sh.in 2016-08-03 18:58:12 +0000
@@ -1,2 +1,2 @@
1find ./ -type f1find ./ -type f
2find ./ -type f -print0 | @KEEPER_TAR_CREATE_BIN@ -0 -a /com/canonical/keeper/helper2find ./ -type f -print0 | @KEEPER_TAR_CREATE_BIN@ -a /com/canonical/keeper/helper

Subscribers

People subscribed via source and target branches

to all changes: