Imported needed files for exclude path functionality
This commit is contained in:
parent
11d1b9bbb6
commit
374166119e
65
libisofs/exclude.c
Normal file
65
libisofs/exclude.c
Normal file
@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
* exclude.c
|
||||
*
|
||||
* Copyright 2006 Philippe Rouquier
|
||||
* Bonfire-app@wanadoo.fr
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "hash.h"
|
||||
#include "exclude.h"
|
||||
|
||||
static struct iso_hash_node *table[HASH_NODES]={0,};
|
||||
static int num=0;
|
||||
|
||||
void
|
||||
iso_exclude_add_path(const char *path)
|
||||
{
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
num += iso_hash_insert(table, path);
|
||||
}
|
||||
|
||||
void
|
||||
iso_exclude_remove_path(const char *path)
|
||||
{
|
||||
if (!num || !path)
|
||||
return;
|
||||
|
||||
num -= iso_hash_remove(table, path);
|
||||
}
|
||||
|
||||
void
|
||||
iso_exclude_empty(void)
|
||||
{
|
||||
if (!num)
|
||||
return;
|
||||
|
||||
iso_hash_empty(table);
|
||||
num=0;
|
||||
}
|
||||
|
||||
int
|
||||
iso_exclude_lookup(const char *path)
|
||||
{
|
||||
if (!num || !path)
|
||||
return 0;
|
||||
|
||||
return iso_hash_lookup(table, path);
|
||||
}
|
35
libisofs/exclude.h
Normal file
35
libisofs/exclude.h
Normal file
@ -0,0 +1,35 @@
|
||||
/***************************************************************************
|
||||
* exclude.h
|
||||
*
|
||||
* Copyright 2006 Philippe Rouquier
|
||||
* Bonfire-app@wanadoo.fr
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef ISO_EXCLUDE_H
|
||||
#define ISO_EXCLUDE_H
|
||||
|
||||
/**
|
||||
* Add a path to ignore when adding a directory recursively.
|
||||
*
|
||||
* \param path The path, on the local filesystem, of the file.
|
||||
*/
|
||||
int
|
||||
iso_exclude_lookup(const char *path);
|
||||
|
||||
#endif /* ISO_EXCLUDE */
|
181
libisofs/hash.c
Normal file
181
libisofs/hash.c
Normal file
@ -0,0 +1,181 @@
|
||||
/***************************************************************************
|
||||
* hash.c
|
||||
*
|
||||
* Copyright 2006 Philippe Rouquier
|
||||
* Bonfire-app@wanadoo.fr
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
static unsigned int
|
||||
iso_hash_path(const char *path)
|
||||
{
|
||||
unsigned int hash_num=0;
|
||||
const char *c;
|
||||
|
||||
c=path;
|
||||
while(*c)
|
||||
hash_num = (hash_num << 15) + (hash_num << 3) + (hash_num >> 3) + *c++;
|
||||
|
||||
return hash_num % HASH_NODES;
|
||||
}
|
||||
|
||||
int
|
||||
iso_hash_lookup(struct iso_hash_node **table, const char *path)
|
||||
{
|
||||
struct iso_hash_node *node;
|
||||
unsigned int hash_num;
|
||||
|
||||
hash_num = iso_hash_path(path);
|
||||
|
||||
node=table[hash_num];
|
||||
|
||||
if (!node)
|
||||
return 0;
|
||||
|
||||
if (!strcmp(path, node->path))
|
||||
return 1;
|
||||
|
||||
while (node->next) {
|
||||
node=node->next;
|
||||
|
||||
if (!strcmp(path, node->path))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct iso_hash_node*
|
||||
iso_hash_node_new (const char *path)
|
||||
{
|
||||
struct iso_hash_node *node;
|
||||
|
||||
/*create an element to be inserted in the hash table */
|
||||
node=malloc(sizeof(struct iso_hash_node));
|
||||
node->path=strdup(path);
|
||||
node->next=NULL;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
int
|
||||
iso_hash_insert(struct iso_hash_node **table, const char *path)
|
||||
{
|
||||
struct iso_hash_node *node;
|
||||
unsigned int hash_num;
|
||||
|
||||
/* find the hash number */
|
||||
hash_num = iso_hash_path(path);
|
||||
|
||||
/* insert it */
|
||||
node = table[hash_num];
|
||||
|
||||
/* unfortunately, we can't safely consider that a path
|
||||
* won't be twice in the hash table so make sure it
|
||||
* doesn't already exists */
|
||||
if (!node) {
|
||||
table[hash_num]=iso_hash_node_new(path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* if it's already in, we don't do anything */
|
||||
if (!strcmp(path, node->path))
|
||||
return 0;
|
||||
|
||||
while (node->next) {
|
||||
node = node->next;
|
||||
|
||||
/* if it's already in, we don't do anything */
|
||||
if (!strcmp (path, node->path))
|
||||
return 0;
|
||||
}
|
||||
|
||||
node->next = iso_hash_node_new(path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
iso_hash_node_free(struct iso_hash_node *node)
|
||||
{
|
||||
free(node->path);
|
||||
free(node);
|
||||
}
|
||||
|
||||
int
|
||||
iso_hash_remove(struct iso_hash_node **table, const char *path)
|
||||
{
|
||||
unsigned int hash_num;
|
||||
struct iso_hash_node *node;
|
||||
|
||||
hash_num = iso_hash_path(path);
|
||||
|
||||
node=table[hash_num];
|
||||
if (!node)
|
||||
return 0;
|
||||
|
||||
if (!strcmp(path, node->path)) {
|
||||
table[hash_num]=node->next;
|
||||
iso_hash_node_free(node);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (node->next) {
|
||||
struct iso_hash_node *prev;
|
||||
|
||||
prev = node;
|
||||
node = node->next;
|
||||
|
||||
if (!strcmp (path, node->path)) {
|
||||
prev->next=node->next;
|
||||
iso_hash_node_free(node);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
iso_hash_empty(struct iso_hash_node **table)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < HASH_NODES; i++) {
|
||||
struct iso_hash_node *node;
|
||||
|
||||
node=table[i];
|
||||
if (!node)
|
||||
continue;
|
||||
|
||||
table[i]=NULL;
|
||||
|
||||
do {
|
||||
struct iso_hash_node *next;
|
||||
|
||||
next=node->next;
|
||||
iso_hash_node_free(node);
|
||||
node=next;
|
||||
} while (node);
|
||||
}
|
||||
}
|
||||
|
69
libisofs/hash.h
Normal file
69
libisofs/hash.h
Normal file
@ -0,0 +1,69 @@
|
||||
/***************************************************************************
|
||||
* hash.h
|
||||
*
|
||||
* Copyright 2006 Philippe Rouquier
|
||||
* Bonfire-app@wanadoo.fr
|
||||
***************************************************************************/
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef ISO_HASH_H
|
||||
#define ISO_HASH_H
|
||||
|
||||
struct iso_hash_node {
|
||||
struct iso_hash_node *next;
|
||||
char *path;
|
||||
};
|
||||
|
||||
#define HASH_NODES 128
|
||||
|
||||
/**
|
||||
* Searches in the hash table if the path exists.
|
||||
*
|
||||
* \param table The hash table.
|
||||
* \param path The path of the file to look for.
|
||||
*
|
||||
* \return 1 if the path exists in the hash table, 0 otherwise.
|
||||
*/
|
||||
int iso_hash_lookup(struct iso_hash_node **table, const char *path);
|
||||
|
||||
/**
|
||||
* Insert a new path in the hash table.
|
||||
*
|
||||
* \param table The hash table.
|
||||
* \param path The path of a file to add to the hash table.
|
||||
*
|
||||
* \return 1 if the file wasn't already in the hash table, 0 otherwise.
|
||||
*/
|
||||
int iso_hash_insert(struct iso_hash_node **table, const char *path);
|
||||
|
||||
/**
|
||||
* Remove a path from the hash table.
|
||||
*
|
||||
* \param table The hash table.
|
||||
* \param path The path of a file to remove from the hash table.
|
||||
*
|
||||
* \return 1 if the file was found and removed, 0 otherwise.
|
||||
*/
|
||||
int iso_hash_remove(struct iso_hash_node **table, const char *path);
|
||||
|
||||
/**
|
||||
* Empty the hash table.
|
||||
*/
|
||||
void iso_hash_empty(struct iso_hash_node **table);
|
||||
|
||||
#endif /* ISO_HASH_H */
|
Loading…
Reference in New Issue
Block a user