Skip to content

Commit

Permalink
Upgrade path cache to generic interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed Dec 10, 2014
1 parent f31c752 commit 8a6198f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 44 deletions.
6 changes: 5 additions & 1 deletion src/filed/dir_cmd.c
Expand Up @@ -2127,7 +2127,11 @@ static void filed_free_jcr(JCR *jcr)
free_bootstrap(jcr);
free_runscripts(jcr->RunScripts);
delete jcr->RunScripts;
free_path_list(jcr);

if (jcr->path_list) {
free_path_list(jcr->path_list);
jcr->path_list = NULL;
}

if (jcr->JobId != 0) {
write_state_file(me->working_directory, "bareos-fd", get_first_port_host_order(me->FDaddrs));
Expand Down
17 changes: 11 additions & 6 deletions src/findlib/create_file.c
Expand Up @@ -87,7 +87,9 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)

#ifdef HAVE_WIN32
if (!bfd->use_backup_api) {
// eliminate invalid windows filename characters from foreign filenames
/*
* Eliminate invalid windows filename characters from foreign filenames
*/
char *ch = (char *)attr->ofname;
if (ch[0] != 0 && ch[1] != 0) {
ch += 2;
Expand Down Expand Up @@ -125,8 +127,10 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
}
break;
case REPLACE_NEVER:
/* Set attributes if we created this directory */
if (attr->type == FT_DIREND && path_list_lookup(jcr, attr->ofname)) {
/*
* Set attributes if we created this directory
*/
if (attr->type == FT_DIREND && path_list_lookup(jcr->path_list, attr->ofname)) {
break;
}
Qmsg(jcr, M_SKIPPED, 0, _("File skipped. Already exists: %s\n"), attr->ofname);
Expand Down Expand Up @@ -225,7 +229,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)

return CF_EXTRACT;

#ifndef HAVE_WIN32 // none of these exist in MS Windows
#ifndef HAVE_WIN32 /* None of these exist in MS Windows */
case FT_RAW: /* Bareos raw device e.g. /dev/sda1 */
case FT_FIFO: /* Bareos fifo to save data */
case FT_SPEC:
Expand Down Expand Up @@ -279,7 +283,9 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
if (attr->type == FT_RAW || attr->type == FT_FIFO) {
btimer_t *tid;
Dmsg1(400, "FT_RAW|FT_FIFO %s\n", attr->ofname);
/* Timeout open() in 60 seconds */
/*
* Timeout open() in 60 seconds
*/
if (attr->type == FT_FIFO) {
Dmsg0(400, "Set FIFO timer\n");
tid = start_thread_timer(jcr, pthread_self(), 60);
Expand All @@ -305,7 +311,6 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
Dmsg1(400, "FT_SPEC %s\n", attr->ofname);
return CF_CREATED;


case FT_LNKSAVED: /* Hard linked, file already saved */
Dmsg2(130, "Hard link %s => %s\n", attr->ofname, attr->olname);
if (link(attr->olname, attr->ofname) != 0) {
Expand Down
82 changes: 48 additions & 34 deletions src/findlib/mkpath.c
Expand Up @@ -55,73 +55,75 @@ typedef struct PrivateCurDir {
char fname[1];
} CurDir;

/* Initialize the path hash table */
static bool path_list_init(JCR *jcr)
/*
* Initialize the path hash table
*/
htable *path_list_init()
{
htable *path_list;
CurDir *elt = NULL;
jcr->path_list = (htable *)malloc(sizeof(htable));

/* Hard to know in advance how many directories will
* be stored in this hash
path_list = (htable *)malloc(sizeof(htable));

/*
* Hard to know in advance how many directories will be stored in this hash
*/
jcr->path_list->init(elt, &elt->link, 10000);
return true;
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
/*
* Add a path to the hash when we create a directory with the replace=NEVER option
*/
bool path_list_add(JCR *jcr, uint32_t len, char *fname)
bool path_list_add(htable *path_list, uint32_t len, char *fname)
{
bool ret = true;
CurDir *item;

if (!jcr->path_list) {
path_list_init(jcr);
if (!path_list) {
return false;
}

/* we store CurDir, fname in the same chunk */
item = (CurDir *)jcr->path_list->hash_malloc(sizeof(CurDir)+len+1);
/*
* 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);
memcpy(item->fname, fname, len + 1);

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

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

void free_path_list(JCR *jcr)
{
if (jcr->path_list) {
jcr->path_list->destroy();
free(jcr->path_list);
jcr->path_list = NULL;
}
return true;
}

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

if (!jcr->path_list) {
if (!path_list) {
return false;
}

/* Strip trailing / */
int len = strlen(fname);
/*
* 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 *)jcr->path_list->lookup(fname);
CurDir *temp = (CurDir *)path_list->lookup(fname);
if (temp) {
found=true;
}
Expand All @@ -132,6 +134,12 @@ bool path_list_lookup(JCR *jcr, char *fname)
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 All @@ -151,8 +159,14 @@ static bool makedir(JCR *jcr, char *path, mode_t mode, int *created)
}

if (jcr->keep_path_list) {
/* When replace=NEVER, we keep track of all directories newly created */
path_list_add(jcr, strlen(path), path);
/*
* When replace = NEVER, we keep track of all directories newly created
*/
if (!jcr->path_list) {
jcr->path_list = path_list_init();
}

path_list_add(jcr->path_list, strlen(path), path);
}

*created = true;
Expand Down
7 changes: 4 additions & 3 deletions src/findlib/protos.h
Expand Up @@ -88,12 +88,13 @@ 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);
void free_path_list(JCR *jcr);
bool path_list_lookup(JCR *jcr, char *fname);
bool path_list_add(JCR *jcr, uint32_t len, char *fname);

/* fstype.c */
bool fstype(const char *fname, char *fs, int fslen);
Expand Down

0 comments on commit 8a6198f

Please sign in to comment.