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
improves matching of patterns for unit description
[src/app-framework-main.git]
/
src
/
wgtpkg-files.c
diff --git
a/src/wgtpkg-files.c
b/src/wgtpkg-files.c
index
06aac83
..
0b55670
100644
(file)
--- a/
src/wgtpkg-files.c
+++ b/
src/wgtpkg-files.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.
@@
-18,11
+20,17
@@
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
-#include <syslog.h>
#include <dirent.h>
#include <stdio.h>
#include <dirent.h>
#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <sys/stat.h>
-#include "wgtpkg.h"
+#include "verbose.h"
+#include "wgtpkg-workdir.h"
+#include "wgtpkg-files.h"
struct fdb {
unsigned int count;
struct fdb {
unsigned int count;
@@
-44,7
+52,7
@@
static unsigned int what_signature(const char *name)
return UINT_MAX;
len = sizeof(distributor_file_prefix)-1;
return UINT_MAX;
len = sizeof(distributor_file_prefix)-1;
- if (
mem
cmp(name, distributor_file_prefix, len))
+ if (
strn
cmp(name, distributor_file_prefix, len))
return 0;
if (name[len] <= '0' || name[len] > '9')
return 0;
return 0;
if (name[len] <= '0' || name[len] > '9')
return 0;
@@
-52,7
+60,7
@@
static unsigned int what_signature(const char *name)
while ('0' <= name[len] && name[len] <= '9') {
nid = 10 * id + (unsigned int)(name[len++] - '0');
if (nid < id || nid == UINT_MAX) {
while ('0' <= name[len] && name[len] <= '9') {
nid = 10 * id + (unsigned int)(name[len++] - '0');
if (nid < id || nid == UINT_MAX) {
-
syslog(LOG_WARNING,
"number too big for %s", name);
+
WARNING(
"number too big for %s", name);
return 0;
}
id = nid;
return 0;
}
id = nid;
@@
-93,7
+101,7
@@
static struct filedesc *get_filedesc(const char *name, int create)
/* allocations */
grow = realloc(allfiles.files, (allfiles.count + 1) * sizeof(struct filedesc *));
if (grow == NULL) {
/* allocations */
grow = realloc(allfiles.files, (allfiles.count + 1) * sizeof(struct filedesc *));
if (grow == NULL) {
-
syslog(LOG_ERR,
"realloc failed in get_filedesc");
+
ERROR(
"realloc failed in get_filedesc");
return NULL;
}
allfiles.files = grow;
return NULL;
}
allfiles.files = grow;
@@
-101,7
+109,7
@@
static struct filedesc *get_filedesc(const char *name, int create)
if (sig) {
grow = realloc(allsignatures.files, (allsignatures.count + 1) * sizeof(struct filedesc *));
if (grow == NULL) {
if (sig) {
grow = realloc(allsignatures.files, (allsignatures.count + 1) * sizeof(struct filedesc *));
if (grow == NULL) {
-
syslog(LOG_ERR,
"second realloc failed in get_filedesc");
+
ERROR(
"second realloc failed in get_filedesc");
return NULL;
}
allsignatures.files = grow;
return NULL;
}
allsignatures.files = grow;
@@
-109,7
+117,7
@@
static struct filedesc *get_filedesc(const char *name, int create)
result = malloc(sizeof(struct filedesc) + strlen(name));
if (!result) {
result = malloc(sizeof(struct filedesc) + strlen(name));
if (!result) {
-
syslog(LOG_ERR,
"calloc failed in get_filedesc");
+
ERROR(
"calloc failed in get_filedesc");
return NULL;
}
return NULL;
}
@@
-147,7
+155,7
@@
static struct filedesc *file_add(const char *name, enum entrytype type)
else if (desc->type == type_unset)
desc->type = type;
else {
else if (desc->type == type_unset)
desc->type = type;
else {
-
syslog(LOG_ERR,
"redeclaration of %s in file_add", name);
+
ERROR(
"redeclaration of %s in file_add", name);
errno = EEXIST;
desc = NULL;
}
errno = EEXIST;
desc = NULL;
}
@@
-226,7
+234,7
@@
struct filedesc *create_signature(unsigned int number)
len = asprintf(&name, "%s%u%s", distributor_file_prefix, number, distributor_file_suffix);
if (len < 0)
len = asprintf(&name, "%s%u%s", distributor_file_prefix, number, distributor_file_suffix);
if (len < 0)
-
syslog(LOG_ERR,
"asprintf failed in create_signature");
+
ERROR(
"asprintf failed in create_signature");
else {
assert(len > 0);
result = file_of_name(name);
else {
assert(len > 0);
result = file_of_name(name);
@@
-246,36
+254,48
@@
void file_clear_flags()
allfiles.files[i]->flags &= flag_signature;
}
allfiles.files[i]->flags &= flag_signature;
}
-static int fill_files_rec(char name[PATH_MAX],
int
offset)
+static int fill_files_rec(char name[PATH_MAX],
unsigned
offset)
{
{
- int len, err;
+ int err, fd;
+ unsigned len;
DIR *dir;
struct dirent *ent;
DIR *dir;
struct dirent *ent;
+ struct stat st;
- if (offset == 0)
- dir = opendir(".");
- else {
- dir = opendir(name);
- name[offset++] = '/';
+ fd = openat(workdirfd, offset ? name : ".", O_DIRECTORY|O_RDONLY);
+ if (fd < 0) {
+ ERROR("openat %.*s failed in fill_files_rec", offset, name);
+ return -1;
}
}
+ dir = fdopendir(fd);
if (!dir) {
if (!dir) {
- syslog(LOG_ERR, "opendir %.*s failed in zwr", offset, name);
+ ERROR("opendir %.*s failed in fill_files_rec", offset, name);
+ close(fd);
return -1;
}
return -1;
}
+ if (offset)
+ name[offset++] = '/';
ent = readdir(dir);
while (ent != NULL) {
ent = readdir(dir);
while (ent != NULL) {
- len = strlen(ent->d_name);
+ len =
(unsigned)
strlen(ent->d_name);
if (ent->d_name[0] == '.' && (len == 1 ||
(ent->d_name[1] == '.' && len == 2)))
;
else if (offset + len >= PATH_MAX) {
closedir(dir);
if (ent->d_name[0] == '.' && (len == 1 ||
(ent->d_name[1] == '.' && len == 2)))
;
else if (offset + len >= PATH_MAX) {
closedir(dir);
-
syslog(LOG_ERR,
"name too long in fill_files_rec");
+
ERROR(
"name too long in fill_files_rec");
errno = ENAMETOOLONG;
return -1;
} else {
memcpy(name + offset, ent->d_name, 1+len);
errno = ENAMETOOLONG;
return -1;
} else {
memcpy(name + offset, ent->d_name, 1+len);
+ if (ent->d_type == DT_UNKNOWN) {
+ fstatat(fd, ent->d_name, &st, 0);
+ if (S_ISREG(st.st_mode))
+ ent->d_type = DT_REG;
+ else if (S_ISDIR(st.st_mode))
+ ent->d_type = DT_DIR;
+ }
switch (ent->d_type) {
case DT_DIR:
if (file_add_directory(name) == NULL) {
switch (ent->d_type) {
case DT_DIR:
if (file_add_directory(name) == NULL) {