Code Review
/
src
/
app-framework-main.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
afm-binding: Common code getting application id
[src/app-framework-main.git]
/
src
/
wgtpkg-pack.c
diff --git
a/src/wgtpkg-pack.c
b/src/wgtpkg-pack.c
index
451d427
..
0f5f70c
100644
(file)
--- a/
src/wgtpkg-pack.c
+++ b/
src/wgtpkg-pack.c
@@
-1,5
+1,7
@@
/*
/*
- Copyright 2015 IoT.bzh
+ Copyright 2015, 2016, 2017 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@
-21,26
+23,31
@@
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
-#include <syslog.h>
#include <getopt.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "verbose.h"
#include <getopt.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "verbose.h"
-#include "wgtpkg.h"
-
-#if !defined(MAXCERT)
-#define MAXCERT 20
-#endif
-#if !defined(DEFAULT_KEY_FILE)
-#define DEFAULT_KEY_FILE "key.pem"
-#endif
-#if !defined(DEFAULT_CERT_FILE)
-#define DEFAULT_CERT_FILE "cert.pem"
-#endif
+#include "wgtpkg-files.h"
+#include "wgtpkg-workdir.h"
+#include "wgtpkg-zip.h"
const char appname[] = "wgtpkg-pack";
const char appname[] = "wgtpkg-pack";
+static void version()
+{
+ printf(
+ "\n"
+ " %s version="AFM_VERSION"\n"
+ "\n"
+ " Copyright (C) 2015, 2016, 2017 \"IoT.bzh\"\n"
+ " AFB comes with ABSOLUTELY NO WARRANTY.\n"
+ " Licence Apache 2\n"
+ "\n",
+ appname
+ );
+}
+
static void usage()
{
printf(
static void usage()
{
printf(
@@
-50,6
+57,7
@@
static void usage()
" -f force overwriting\n"
" -q quiet\n"
" -v verbose\n"
" -f force overwriting\n"
" -q quiet\n"
" -v verbose\n"
+ " -V version\n"
"\n",
appname
);
"\n",
appname
);
@@
-61,6
+69,7
@@
static struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "quiet", no_argument, NULL, 'q' },
{ "verbose", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ "quiet", no_argument, NULL, 'q' },
{ "verbose", no_argument, NULL, 'v' },
+ { "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 }
};
{ NULL, 0, NULL, 0 }
};
@@
-71,12
+80,12
@@
int main(int ac, char **av)
char *wgtfile, *directory, *x;
struct stat s;
char *wgtfile, *directory, *x;
struct stat s;
-
openlog(appname, LOG_PERROR, LOG_USER
);
+
LOGUSER(appname
);
force = 0;
wgtfile = directory = NULL;
for (;;) {
force = 0;
wgtfile = directory = NULL;
for (;;) {
- i = getopt_long(ac, av, "qvhfo:", options, NULL);
+ i = getopt_long(ac, av, "qv
V
hfo:", options, NULL);
if (i < 0)
break;
switch (i) {
if (i < 0)
break;
switch (i) {
@@
-96,52
+105,55
@@
int main(int ac, char **av)
case 'h':
usage();
return 0;
case 'h':
usage();
return 0;
+ case 'V':
+ version();
+ return 0;
case ':':
case ':':
-
syslog(LOG_ERR,
"missing argument");
+
ERROR(
"missing argument");
return 1;
default:
return 1;
default:
-
syslog(LOG_ERR,
"unrecognized option");
+
ERROR(
"unrecognized option");
return 1;
}
}
/* remaining arguments and final checks */
if (optind >= ac) {
return 1;
}
}
/* remaining arguments and final checks */
if (optind >= ac) {
-
syslog(LOG_ERR,
"no directory set");
+
ERROR(
"no directory set");
return 1;
}
directory = av[optind++];
if (optind < ac) {
return 1;
}
directory = av[optind++];
if (optind < ac) {
-
syslog(LOG_ERR,
"extra parameters found");
+
ERROR(
"extra parameters found");
return 1;
}
/* set default values */
if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) {
return 1;
}
/* set default values */
if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) {
-
syslog(LOG_ERR,
"asprintf failed");
+
ERROR(
"asprintf failed");
return 1;
}
/* check values */
if (stat(directory, &s)) {
return 1;
}
/* check values */
if (stat(directory, &s)) {
-
syslog(LOG_ERR,
"can't find directory %s", directory);
+
ERROR(
"can't find directory %s", directory);
return 1;
}
if (!S_ISDIR(s.st_mode)) {
return 1;
}
if (!S_ISDIR(s.st_mode)) {
-
syslog(LOG_ERR,
"%s isn't a directory", directory);
+
ERROR(
"%s isn't a directory", directory);
return 1;
}
if (access(wgtfile, F_OK) == 0 && force == 0) {
return 1;
}
if (access(wgtfile, F_OK) == 0 && force == 0) {
-
syslog(LOG_ERR,
"can't overwrite existing %s", wgtfile);
+
ERROR(
"can't overwrite existing %s", wgtfile);
return 1;
}
return 1;
}
-
notice
("-- PACKING widget %s from directory %s", wgtfile, directory);
+
NOTICE
("-- PACKING widget %s from directory %s", wgtfile, directory);
/* creates an existing widget (for realpath it must exist) */
i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0644);
if (i < 0) {
/* creates an existing widget (for realpath it must exist) */
i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0644);
if (i < 0) {
-
syslog(LOG_ERR,
"can't write widget %s", wgtfile);
+
ERROR(
"can't write widget %s", wgtfile);
return 1;
}
close(i);
return 1;
}
close(i);
@@
-149,7
+161,7
@@
int main(int ac, char **av)
/* compute absolutes paths */
x = realpath(wgtfile, NULL);
if (x == NULL) {
/* compute absolutes paths */
x = realpath(wgtfile, NULL);
if (x == NULL) {
-
syslog(LOG_ERR,
"realpath failed for %s",wgtfile);
+
ERROR(
"realpath failed for %s",wgtfile);
return 1;
}
wgtfile = x;
return 1;
}
wgtfile = x;