basic: add new helper call empty_or_dash_to_null()
We have a function like this at two places already. Let's unify it in one generic location and let's port a number of users over.
This commit is contained in:
+2
-4
@@ -78,8 +78,7 @@ static int export_tar(int argc, char *argv[], void *userdata) {
|
||||
|
||||
if (argc >= 3)
|
||||
path = argv[2];
|
||||
if (empty_or_dash(path))
|
||||
path = NULL;
|
||||
path = empty_or_dash_to_null(path);
|
||||
|
||||
determine_compression_from_filename(path);
|
||||
|
||||
@@ -155,8 +154,7 @@ static int export_raw(int argc, char *argv[], void *userdata) {
|
||||
|
||||
if (argc >= 3)
|
||||
path = argv[2];
|
||||
if (empty_or_dash(path))
|
||||
path = NULL;
|
||||
path = empty_or_dash_to_null(path);
|
||||
|
||||
determine_compression_from_filename(path);
|
||||
|
||||
|
||||
@@ -117,15 +117,13 @@ static int import_fs(int argc, char *argv[], void *userdata) {
|
||||
|
||||
if (argc >= 2)
|
||||
path = argv[1];
|
||||
if (empty_or_dash(path))
|
||||
path = NULL;
|
||||
path = empty_or_dash_to_null(path);
|
||||
|
||||
if (argc >= 3)
|
||||
local = argv[2];
|
||||
else if (path)
|
||||
local = basename(path);
|
||||
if (empty_or_dash(local))
|
||||
local = NULL;
|
||||
local = empty_or_dash_to_null(local);
|
||||
|
||||
if (local) {
|
||||
if (!machine_name_is_valid(local)) {
|
||||
|
||||
+4
-8
@@ -49,15 +49,13 @@ static int import_tar(int argc, char *argv[], void *userdata) {
|
||||
|
||||
if (argc >= 2)
|
||||
path = argv[1];
|
||||
if (empty_or_dash(path))
|
||||
path = NULL;
|
||||
path = empty_or_dash_to_null(path);
|
||||
|
||||
if (argc >= 3)
|
||||
local = argv[2];
|
||||
else if (path)
|
||||
local = basename(path);
|
||||
if (empty_or_dash(local))
|
||||
local = NULL;
|
||||
local = empty_or_dash_to_null(local);
|
||||
|
||||
if (local) {
|
||||
r = tar_strip_suffixes(local, &ll);
|
||||
@@ -145,15 +143,13 @@ static int import_raw(int argc, char *argv[], void *userdata) {
|
||||
|
||||
if (argc >= 2)
|
||||
path = argv[1];
|
||||
if (empty_or_dash(path))
|
||||
path = NULL;
|
||||
path = empty_or_dash_to_null(path);
|
||||
|
||||
if (argc >= 3)
|
||||
local = argv[2];
|
||||
else if (path)
|
||||
local = basename(path);
|
||||
if (empty_or_dash(local))
|
||||
local = NULL;
|
||||
local = empty_or_dash_to_null(local);
|
||||
|
||||
if (local) {
|
||||
r = raw_strip_suffixes(local, &ll);
|
||||
|
||||
+2
-4
@@ -64,8 +64,7 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
|
||||
local = l;
|
||||
}
|
||||
|
||||
if (empty_or_dash(local))
|
||||
local = NULL;
|
||||
local = empty_or_dash_to_null(local);
|
||||
|
||||
if (local) {
|
||||
r = tar_strip_suffixes(local, &ll);
|
||||
@@ -151,8 +150,7 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
|
||||
local = l;
|
||||
}
|
||||
|
||||
if (empty_or_dash(local))
|
||||
local = NULL;
|
||||
local = empty_or_dash_to_null(local);
|
||||
|
||||
if (local) {
|
||||
r = raw_strip_suffixes(local, &ll);
|
||||
|
||||
Reference in New Issue
Block a user