Skip to content

Commit

Permalink
Move path_list code from findlib to normal lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen authored and pstorz committed Mar 27, 2015
1 parent 3f65364 commit 9d5d356
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 104 deletions.
90 changes: 0 additions & 90 deletions src/findlib/mkpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,96 +50,6 @@
#define lchmod chmod
#endif

typedef struct PrivateCurDir {
hlink link;
char fname[1];
} CurDir;

/*
* Initialize the path hash table
*/
htable *path_list_init()
{
htable *path_list;
CurDir *elt = NULL;

path_list = (htable *)malloc(sizeof(htable));

/*
* Hard to know in advance how many directories will be stored in this hash
*/
path_list->init(elt, &elt->link, 10000);

return path_list;
}

/*
* Add a path to the hash when we create a directory with the replace=NEVER option
*/
bool path_list_add(htable *path_list, uint32_t len, char *fname)
{
CurDir *item;

if (!path_list) {
return false;
}

/*
* We store CurDir, fname in the same chunk
*/
item = (CurDir *)path_list->hash_malloc(sizeof(CurDir) + len + 1);

memset(item, 0, sizeof(CurDir));
memcpy(item->fname, fname, len + 1);

path_list->insert(item->fname, item);

Dmsg1(dbglvl, "add fname=<%s>\n", fname);

return true;
}

bool path_list_lookup(htable *path_list, char *fname)
{
int len;
bool found = false;
char bkp;

if (!path_list) {
return false;
}

/*
* Strip trailing /
*/
len = strlen(fname);
if (len == 0) {
return false;
}
len--;
bkp = fname[len];

if (fname[len] == '/') { /* strip any trailing slash */
fname[len] = 0;
}

CurDir *temp = (CurDir *)path_list->lookup(fname);
if (temp) {
found=true;
}

Dmsg2(dbglvl, "lookup <%s> %s\n", fname, found?"ok":"not ok");

fname[len] = bkp; /* restore last / */
return found;
}

void free_path_list(htable *path_list)
{
path_list->destroy();
free(path_list);
}

static bool makedir(JCR *jcr, char *path, mode_t mode, int *created)
{
struct stat statp;
Expand Down
4 changes: 0 additions & 4 deletions src/findlib/protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ void ff_pkt_set_link_digest(FF_PKT *ff_pkt,
uint32_t len);

/* makepath.c */
htable *path_list_init();
bool path_list_lookup(htable *path_list, char *fname);
bool path_list_add(htable *path_list, uint32_t len, char *fname);
void free_path_list(htable *path_list);
bool makepath(ATTR *attr, const char *path, mode_t mode,
mode_t parent_mode, uid_t owner, gid_t group,
bool keep_dir_modes);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ LIBBAREOS_SRCS = address_conf.c alist.c attr.c attribs.c base64.c \
crypto_gnutls.c crypto_none.c crypto_nss.c crypto_openssl.c \
crypto_wrap.c daemon.c devlock.c dlist.c edit.c fnmatch.c \
guid_to_name.c hmac.c htable.c jcr.c lockmgr.c md5.c \
mem_pool.c message.c mntent_cache.c passphrase.c plugins.c \
poll.c priv.c queue.c rblist.c runscript.c rwlock.c scan.c \
scsi_crypto.c scsi_lli.c scsi_tapealert.c sellist.c serial.c \
sha1.c signal.c smartall.c tls_gnutls.c tls_none.c tls_nss.c \
tls_openssl.c tree.c util.c var.c watchdog.c workq.c
mem_pool.c message.c mntent_cache.c passphrase.c path_list.c \
plugins.c poll.c priv.c queue.c rblist.c runscript.c rwlock.c \
scan.c scsi_crypto.c scsi_lli.c scsi_tapealert.c sellist.c \
serial.c sha1.c signal.c smartall.c tls_gnutls.c tls_none.c \
tls_nss.c tls_openssl.c tree.c util.c var.c watchdog.c workq.c

LIBBAREOS_OBJS = $(LIBBAREOS_SRCS:.c=.o)
LIBBAREOS_LOBJS = $(LIBBAREOS_SRCS:.c=.lo)
Expand Down
120 changes: 120 additions & 0 deletions src/lib/path_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

/*
* Kern Sibbald, September MMVII
*/

#include "bareos.h"

#define dbglvl 50

typedef struct PrivateCurDir {
hlink link;
char fname[1];
} CurDir;

/*
* Initialize the path hash table
*/
htable *path_list_init()
{
htable *path_list;
CurDir *elt = NULL;

path_list = (htable *)malloc(sizeof(htable));

/*
* Hard to know in advance how many directories will be stored in this hash
*/
path_list->init(elt, &elt->link, 10000);

return path_list;
}

/*
* Add a path to the hash when we create a directory with the replace=NEVER option
*/
bool path_list_add(htable *path_list, uint32_t len, const char *fname)
{
CurDir *item;

if (!path_list) {
return false;
}

/*
* We store CurDir, fname in the same chunk
*/
item = (CurDir *)path_list->hash_malloc(sizeof(CurDir) + len + 1);

memset(item, 0, sizeof(CurDir));
memcpy(item->fname, fname, len + 1);

path_list->insert(item->fname, item);

Dmsg1(dbglvl, "add fname=<%s>\n", fname);

return true;
}

bool path_list_lookup(htable *path_list, const char *fname)
{
int len;
bool found = false;
POOLMEM *filename;

if (!path_list) {
return false;
}

filename = get_pool_memory(PM_FNAME);
pm_strcpy(filename, fname);

/*
* Strip trailing /
*/
len = strlen(filename);
if (len == 0) {
free_pool_memory(filename);
return false;
}
len--;

if (filename[len] == '/') { /* strip any trailing slash */
filename[len] = 0;
}

CurDir *temp = (CurDir *)path_list->lookup(filename);
if (temp) {
found = true;
}

Dmsg2(dbglvl, "lookup <%s> %s\n", filename, found ? "ok" : "not ok");

return found;
}

void free_path_list(htable *path_list)
{
path_list->destroy();
free(path_list);
}
6 changes: 6 additions & 0 deletions src/lib/protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ void register_message_callback(void msg_callback(int type, char *msg));
/* passphrase.c */
char *generate_crypto_passphrase(int length);

/* path_list.c */
htable *path_list_init();
bool path_list_lookup(htable *path_list, const char *fname);
bool path_list_add(htable *path_list, uint32_t len, const char *fname);
void free_path_list(htable *path_list);

/* poll.c */
int wait_for_readable_fd(int fd, int sec, bool ignore_interupts);
int wait_for_writable_fd(int fd, int sec, bool ignore_interupts);
Expand Down
10 changes: 5 additions & 5 deletions src/win32/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ LIBBAREOS_SRCS = address_conf.c alist.c attr.c attribs.c base64.c \
crypto_gnutls.c crypto_none.c crypto_nss.c crypto_openssl.c \
crypto_wrap.c daemon.c devlock.c dlist.c edit.c fnmatch.c \
guid_to_name.c hmac.c htable.c jcr.c lockmgr.c md5.c \
mem_pool.c message.c mntent_cache.c passphrase.c plugins.c \
poll.c priv.c queue.c rblist.c runscript.c rwlock.c scan.c \
scsi_crypto.c scsi_lli.c sellist.c serial.c sha1.c signal.c \
smartall.c tls_gnutls.c tls_none.c tls_nss.c tls_openssl.c \
tree.c util.c var.c watchdog.c workq.c
mem_pool.c message.c mntent_cache.c passphrase.c path_list.c \
plugins.c poll.c priv.c queue.c rblist.c runscript.c rwlock.c \
scan.c scsi_crypto.c scsi_lli.c sellist.c serial.c sha1.c \
signal.c smartall.c tls_gnutls.c tls_none.c tls_nss.c \
tls_openssl.c tree.c util.c var.c watchdog.c workq.c
LIBBAREOS_OBJS = $(LIBBAREOS_SRCS:.c=.o)

LIBBAREOSCFG_SRCS = ini.c lex.c parse_bsr.c
Expand Down

0 comments on commit 9d5d356

Please sign in to comment.