Reduces memory occupation for hardlinks and empty dirs.

This commit is contained in:
Andrea Mazzoleni 2013-05-30 23:50:26 +02:00
parent 1633fb2a89
commit f8420e1dff
4 changed files with 14 additions and 9 deletions

View file

@ -10,6 +10,7 @@ SnapRAID HISTORY
excluded.
* In Windows applies filters in case insensitive way.
* The Windows binaries are now built with gcc 4.7.2.
* Reduced memory occupation for hardlinks and directories.
3.0 2013/3
==========

11
elem.c
View file

@ -262,7 +262,7 @@ int filter_content(tommy_list* contentlist, const char* path)
/* FNM_PATHNAME because we are comparing full path */
/* FNM_NOESCAPE because the pattern is also a path, surely without escape chars */
/* FNM_NOCASEINWIN ignore case only in windows */
/* FNM_CASEINSENSITIVE_FOR_WIN ignore case only in windows */
if (fnmatch(content->content, path, FNM_PATHNAME | FNM_NOESCAPE | FNM_CASEINSENSITIVE_FOR_WIN) == 0)
return -1;
@ -413,8 +413,8 @@ struct snapraid_link* link_alloc(const char* sub, const char* linkto, unsigned l
struct snapraid_link* link;
link = malloc_nofail(sizeof(struct snapraid_link));
pathcpy(link->sub, sizeof(link->sub), sub);
pathcpy(link->linkto, sizeof(link->linkto), linkto);
link->sub = strdup_nofail(sub);
link->linkto = strdup_nofail(linkto);
link->flag = link_flag;
return link;
@ -422,6 +422,8 @@ struct snapraid_link* link_alloc(const char* sub, const char* linkto, unsigned l
void link_free(struct snapraid_link* link)
{
free(link->sub);
free(link->linkto);
free(link);
}
@ -437,7 +439,7 @@ struct snapraid_dir* dir_alloc(const char* sub)
struct snapraid_dir* dir;
dir = malloc_nofail(sizeof(struct snapraid_dir));
pathcpy(dir->sub, sizeof(dir->sub), sub);
dir->sub = strdup_nofail(sub);
dir->flag = 0;
return dir;
@ -445,6 +447,7 @@ struct snapraid_dir* dir_alloc(const char* sub)
void dir_free(struct snapraid_dir* dir)
{
free(dir->sub);
free(dir);
}

6
elem.h
View file

@ -207,8 +207,8 @@ struct snapraid_file {
*/
struct snapraid_link {
unsigned flag; /**< FILE_IS_* flags. */
char sub[PATH_MAX]; /**< Sub path of the file. Without the disk dir. The disk is implicit. */
char linkto[PATH_MAX]; /**< Link to. */
char* sub; /**< Sub path of the file. Without the disk dir. The disk is implicit. */
char* linkto; /**< Link to. */
/* nodes for data structures */
tommy_node nodelist;
@ -220,7 +220,7 @@ struct snapraid_link {
*/
struct snapraid_dir {
unsigned flag; /**< FILE_IS_* flags. */
char sub[PATH_MAX]; /**< Sub path of the file. Without the disk dir. The disk is implicit. */
char* sub; /**< Sub path of the file. Without the disk dir. The disk is implicit. */
/* nodes for data structures */
tommy_node nodelist;

5
scan.c
View file

@ -112,7 +112,8 @@ static void scan_link(struct snapraid_scan* scan, struct snapraid_state* state,
++scan->count_change;
/* update it */
pathcpy(link->linkto, sizeof(link->linkto), linkto);
free(link->linkto);
link->linkto = strdup_nofail(linkto);
link_flag_let(link, link_flag, FILE_IS_LINK_MASK);
/* nothing more to do */
@ -618,7 +619,7 @@ static int scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, in
if (filter_path(&state->filterlist, disk->name, sub_next) == 0) {
#if HAVE_LSTAT_EX
/* get inode info about the file, Windows needs an additional step */
/* also for hardlink, the real size of the file is read only with this function */
/* also for hardlink, the real size of the file is read here */
if (lstat_ex(path_next, &st) != 0) {
fprintf(stderr, "Error in stat_inode file '%s'. %s.\n", path_next, strerror(errno));
exit(EXIT_FAILURE);