* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: holding.c,v 1.17.2.12.4.3.2.10.2.2 2004/10/21 13:12:29 martinea Exp $
+ * $Id: holding.c,v 1.56 2006/06/09 23:07:26 martinea Exp $
*
* Functions to access holding disk
*/
#include "util.h"
#include "holding.h"
#include "fileheader.h"
-#include "util.h"
#include "logfile.h"
-static sl_t *scan_holdingdisk P((sl_t *holding_list, char *diskdir, int verbose));
+/*
+ * utilities */
+
+/* Is fname a directory?
+ *
+ * @param fname: filename (fully qualified)
+ * @returns: boolean
+ */
+static int is_dir(char *fname);
+
+/* sanity check that datestamp is of the form YYYYMMDD or
+ * YYYYMMDDhhmmss
+ *
+ * @param fname: a filename (without directory)
+ * @returns: boolean
+ */
+static int is_datestr(char *fname);
+
+/*
+ * Static variables */
+static int verbose = 0;
-int is_dir(fname)
-char *fname;
+/*
+ * Static functions */
+
+static int
+is_dir(
+ char *fname)
{
struct stat statbuf;
return (statbuf.st_mode & S_IFDIR) == S_IFDIR;
}
-int is_emptyfile(fname)
-char *fname;
+static int
+is_emptyfile(
+ char *fname)
{
struct stat statbuf;
if(stat(fname, &statbuf) == -1) return 0;
- return (statbuf.st_mode & S_IFDIR) != S_IFDIR && statbuf.st_size == 0;
+ return ((statbuf.st_mode & S_IFDIR) != S_IFDIR) &&
+ (statbuf.st_size == (off_t)0);
}
-int is_datestr(fname)
-char *fname;
-/* sanity check on datestamp of the form YYYYMMDD or YYYYMMDDhhmmss*/
+static int
+is_datestr(
+ char *fname)
{
char *cp;
int ch, num, date, year, month, hour, minute, second;
return 1;
}
+/*
+ * Verbosity
+ */
+int
+holding_set_verbosity(int v)
+{
+ int old = verbose;
+ verbose = v;
+ return old;
+}
+
+/*
+ * Holding directories
+ */
-int non_empty(fname)
-char *fname;
+static void
+holding_get_directories_per_disk(
+ char *hdisk,
+ sl_t *date_list,
+ int fullpaths,
+ sl_t *rv)
{
DIR *dir;
- struct dirent *entry;
- int gotentry;
-
- if((dir = opendir(fname)) == NULL)
- return 0;
+ struct dirent *workdir;
+ char *hdir = NULL;
+ sle_t *dl;
+ int date_found;
+
+ if ((dir = opendir(hdisk)) == NULL) {
+ if (verbose && errno != ENOENT)
+ printf(_("Warning: could not open holding disk %s: %s\n"),
+ hdisk, strerror(errno));
+ return;
+ }
- gotentry = 0;
- while(!gotentry && (entry = readdir(dir)) != NULL) {
- gotentry = !is_dot_or_dotdot(entry->d_name);
+ if (verbose)
+ printf(_("Scanning %s...\n"), hdisk);
+
+ while ((workdir = readdir(dir)) != NULL) {
+ if (is_dot_or_dotdot(workdir->d_name))
+ continue;
+
+ if(verbose)
+ printf(" %s: ", workdir->d_name);
+
+ hdir = newvstralloc(hdir,
+ hdisk, "/", workdir->d_name,
+ NULL);
+
+ /* filter out various undesirables */
+ if (!is_dir(hdir)) {
+ if (verbose)
+ puts(_("skipping cruft file, perhaps you should delete it."));
+ } else if (!is_datestr(workdir->d_name)) {
+ /* EXT2/3 leave these in the root of each volume */
+ if (strcmp(workdir->d_name, "lost+found")==0)
+ puts(_("skipping system directory"));
+ if (verbose)
+ puts(_("skipping cruft directory, perhaps you should delete it."));
+ } else {
+ /* found a holding directory -- keep it */
+ if (date_list) {
+ date_found = 0;
+ for (dl= date_list->first; dl != NULL; dl = dl->next) {
+ if (strcmp(dl->name, workdir->d_name) == 0) {
+ date_found = 1;
+ break;
+ }
+ }
+ } else {
+ date_found = 1;
+ }
+ if (date_found == 1) {
+ if (fullpaths)
+ rv = insert_sort_sl(rv, hdir);
+ else
+ rv = insert_sort_sl(rv, workdir->d_name);
+ if (verbose) {
+ puts(_("found Amanda directory."));
+ }
+ }
+ }
}
- closedir(dir);
- return gotentry;
+ if (hdir) amfree(hdir);
}
-sl_t *scan_holdingdisk(holding_list, diskdir, verbose)
-sl_t *holding_list;
-char *diskdir;
-int verbose;
+sl_t *
+holding_get_directories(
+ char *hdisk,
+ sl_t *date_list,
+ int fullpaths)
{
- DIR *topdir;
- struct dirent *workdir;
- char *entryname = NULL;
+ holdingdisk_t *hdisk_conf;
+ sl_t *rv;
- if((topdir = opendir(diskdir)) == NULL) {
- if(verbose && errno != ENOENT)
- printf("Warning: could not open holding dir %s: %s\n",
- diskdir, strerror(errno));
- return holding_list;
+ rv = new_sl();
+ if (!rv) {
+ return NULL;
}
- /* find all directories of the right format */
+ /* call _per_disk for the hdisk we were given, or for all
+ * hdisks if we were given NULL */
+ if (hdisk) {
+ holding_get_directories_per_disk(hdisk, date_list, fullpaths, rv);
+ } else {
+ for (hdisk_conf = getconf_holdingdisks();
+ hdisk_conf != NULL;
+ hdisk_conf = hdisk_conf->next) {
+ hdisk = holdingdisk_get_diskdir(hdisk_conf);
+ holding_get_directories_per_disk(hdisk, date_list, fullpaths, rv);
+ }
+ }
- if(verbose)
- printf("Scanning %s...\n", diskdir);
- while((workdir = readdir(topdir)) != NULL) {
- if(is_dot_or_dotdot(workdir->d_name)
- || strcmp(workdir->d_name, "lost+found") == 0) {
+ return rv;
+}
+
+/*
+ * Holding files
+ */
+static void
+holding_get_files_per_dir(
+ char *hdir,
+ int fullpaths,
+ sl_t *rv)
+{
+ DIR *dir;
+ struct dirent *workdir;
+ char *hfile = NULL;
+ dumpfile_t dumpf;
+ int dumpf_ok;
+
+ if ((dir = opendir(hdir)) == NULL) {
+ if (verbose && errno != ENOENT)
+ printf(_("Warning: could not open holding dir %s: %s\n"),
+ hdir, strerror(errno));
+ return;
+ }
+
+ if (verbose)
+ printf(_("Scanning %s...\n"), hdir);
+
+ while ((workdir = readdir(dir)) != NULL) {
+ if (is_dot_or_dotdot(workdir->d_name))
+ continue;
+
+ hfile = newvstralloc(hfile,
+ hdir, "/", workdir->d_name,
+ NULL);
+
+ /* filter out various undesirables */
+ if (is_emptyfile(hfile))
+ continue;
+
+ if (is_dir(hfile)) {
+ if (verbose)
+ printf(_("%s: ignoring directory\n"), hfile);
+ continue;
+ }
+
+ if (!(dumpf_ok=holding_file_get_dumpfile(hfile, &dumpf)) ||
+ dumpf.type != F_DUMPFILE) {
+ if (dumpf_ok && dumpf.type == F_CONT_DUMPFILE)
+ continue; /* silently skip expected file */
+ if (verbose)
+ printf(_("%s: not a dumpfile\n"), hfile);
+ continue;
+ }
+
+ if (dumpf.dumplevel < 0 || dumpf.dumplevel > 9) {
+ if (verbose)
+ printf(_("%s: ignoring file with bogus dump level %d.\n"),
+ hfile, dumpf.dumplevel);
continue;
}
- entryname = newvstralloc(entryname,
- diskdir, "/", workdir->d_name, NULL);
- if(verbose) {
- printf(" %s: ", workdir->d_name);
- }
- if(!is_dir(entryname)) {
- if(verbose)
- puts("skipping cruft file, perhaps you should delete it.");
- } else if(!is_datestr(workdir->d_name)) {
- if(verbose)
- puts("skipping cruft directory, perhaps you should delete it.");
- } else {
- holding_list = insert_sort_sl(holding_list, workdir->d_name);
- if(verbose)
- puts("found Amanda directory.");
- }
+
+ /* found a holding file -- keep it */
+ if (fullpaths)
+ rv = insert_sort_sl(rv, hfile);
+ else
+ rv = insert_sort_sl(rv, workdir->d_name);
}
- closedir(topdir);
- amfree(entryname);
- return holding_list;
+
+ if (hfile) amfree(hfile);
}
+sl_t *
+holding_get_files(
+ char *hdir,
+ sl_t *date_list,
+ int fullpaths)
+{
+ sl_t *hdirs;
+ sle_t *e;
+ sl_t *rv;
-sl_t *scan_holdingdir(holding_list, holdp, datestamp)
-sl_t *holding_list;
-holdingdisk_t *holdp;
-char *datestamp;
+ rv = new_sl();
+ if (!rv) {
+ return NULL;
+ }
+
+ /* call _per_dir for the hdir we were given, or for all
+ * hdir if we were given NULL */
+ if (hdir) {
+ holding_get_files_per_dir(hdir, fullpaths, rv);
+ } else {
+ hdirs = holding_get_directories(NULL, date_list, 1);
+ for (e = hdirs->first; e != NULL; e = e->next) {
+ holding_get_files_per_dir(e->name, fullpaths, rv);
+ }
+ }
+
+ return rv;
+}
+
+sl_t *
+holding_get_files_for_flush(
+ sl_t *dateargs,
+ int interactive)
{
- DIR *workdir;
- struct dirent *entry;
- char *dirname = NULL;
- char *destname = NULL;
+ sl_t *date_list;
+ sl_t *file_list;
+ sl_t *result_list;
+ sle_t *datearg;
+ sle_t *date, *next_date;
+ sle_t *file_elt;
disk_t *dp;
- dumpfile_t file;
+ char *host;
+ char *disk;
+ char *datestamp;
+ filetype_t filetype;
+
+ /* make date_list the intersection of available holding directories and
+ * the dateargs parameter. */
+ if (dateargs) {
+ int ok;
+
+ date_list = pick_all_datestamp(verbose);
+ for (date = date_list->first; date != NULL;) {
+ next_date = date->next;
+ ok = 0;
+ for(datearg=dateargs->first; datearg != NULL && ok==0;
+ datearg = datearg->next) {
+ ok = match_datestamp(datearg->name, date->name);
+ }
+ if(ok == 0) { /* remove dir */
+ remove_sl(date_list, date);
+ }
+ date = next_date;
+ }
+ }
+ else {
+ /* no date args were provided, so use everything */
+ if (interactive)
+ date_list = pick_datestamp(verbose);
+ else
+ date_list = pick_all_datestamp(verbose);
+ }
- dirname = vstralloc(holdp->diskdir, "/", datestamp, NULL);
- if((workdir = opendir(dirname)) == NULL) {
- if(errno != ENOENT)
- log_add(L_INFO, "%s: could not open dir: %s",
- dirname, strerror(errno));
- amfree(dirname);
- return holding_list;
+ result_list = new_sl();
+ if (!result_list) {
+ return NULL;
}
- chdir(dirname);
- while((entry = readdir(workdir)) != NULL) {
- if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
- continue;
- if(is_emptyfile(entry->d_name))
- continue;
+ /* loop over *all* files, checking each one */
+ file_list = holding_get_files(NULL, date_list, 1);
+ for (file_elt = file_list->first; file_elt != NULL; file_elt = file_elt->next) {
+ /* get info on that file */
+ filetype = holding_file_read_header(file_elt->name, &host, &disk, NULL, &datestamp);
+ if (filetype != F_DUMPFILE)
+ continue;
+
+ /* check that the hostname and disk are in the disklist */
+ dp = lookup_disk(host, disk);
+ if (dp == NULL) {
+ if (verbose)
+ printf(_("%s: disk %s:%s not in database, skipping it."),
+ file_elt->name, host, disk);
+ continue;
+ }
+
+ /* passed all tests -- we'll flush this file */
+ result_list = insert_sort_sl(result_list, file_elt->name);
+ }
- destname = newvstralloc(destname,
- dirname, "/", entry->d_name,
- NULL);
- get_dumpfile(destname, &file);
- if( file.type != F_DUMPFILE) {
- if( file.type != F_CONT_DUMPFILE )
- log_add(L_INFO, "%s: ignoring cruft file.", entry->d_name);
- continue;
- }
+ if (date_list) free_sl(date_list);
+ if (file_list) free_sl(file_list);
- dp = lookup_disk(file.name, file.disk);
+ return result_list;
+}
- if (dp == NULL) {
- log_add(L_INFO, "%s: disk %s:%s not in database, skipping it.",
- entry->d_name, file.name, file.disk);
- continue;
- }
+sl_t *
+holding_get_file_chunks(char *hfile)
+{
+ dumpfile_t file;
+ char *filename;
+ sl_t *rv = new_sl();
- if(file.dumplevel < 0 || file.dumplevel > 9) {
- log_add(L_INFO, "%s: ignoring file with bogus dump level %d.",
- entry->d_name, file.dumplevel);
- continue;
- }
+ if (!rv) {
+ return NULL;
+ }
- holding_list = append_sl(holding_list, destname);
+ /* Loop through all cont_filenames (subsequent chunks) */
+ filename = stralloc(hfile);
+ while (filename != NULL && filename[0] != '\0') {
+ /* get the header to look for cont_filename */
+ if (!holding_file_get_dumpfile(filename, &file)) {
+ if (verbose)
+ printf(_("holding_get_file_chunks: open of %s failed.\n"), filename);
+ amfree(filename);
+ return rv;
+ }
+
+ /* add the file to the results */
+ insert_sort_sl(rv, filename);
+
+ /* and go on to the next chunk */
+ filename = newstralloc(filename, file.cont_filename);
}
- closedir(workdir);
- amfree(dirname);
- amfree(destname);
- return holding_list;
+ amfree(filename);
+ return rv;
+}
+
+off_t
+holding_file_size(
+ char *hfile,
+ int strip_headers)
+{
+ dumpfile_t file;
+ char *filename;
+ off_t size = (off_t)0;
+ struct stat finfo;
+
+ /* (note: we don't use holding_get_file_chunks here because that would
+ * entail opening each file twice) */
+
+ /* Loop through all cont_filenames (subsequent chunks) */
+ filename = stralloc(hfile);
+ while (filename != NULL && filename[0] != '\0') {
+ /* stat the file for its size */
+ if (stat(filename, &finfo) == -1) {
+ if (verbose)
+ printf(_("stat %s: %s\n"), filename, strerror(errno));
+ return (off_t)-1;
+ }
+ size += (finfo.st_size+(off_t)1023)/(off_t)1024;
+ if (strip_headers)
+ size -= (off_t)(DISK_BLOCK_BYTES / 1024);
+
+ /* get the header to look for cont_filename */
+ if (!holding_file_get_dumpfile(filename, &file)) {
+ if (verbose)
+ printf(_("holding_file_size: open of %s failed.\n"), filename);
+ amfree(filename);
+ return (off_t)-1;
+ }
+
+ /* on to the next chunk */
+ filename = newstralloc(filename, file.cont_filename);
+ }
+ amfree(filename);
+ return size;
}
-sl_t *get_flush(dateargs, datestamp, amflush, verbose)
-sl_t *dateargs;
-char *datestamp; /* don't do this date */
-int amflush, verbose;
+int
+holding_file_unlink(
+ char *hfile)
{
- sl_t *holding_list;
- sl_t *date_list;
- sle_t *datearg;
- sle_t *date, *next_date;
- holdingdisk_t *hdisk;
- char current_dir[1000];
+ sl_t *chunklist;
+ sle_t *chunk;
+
+ chunklist = holding_get_file_chunks(hfile);
+ if (!chunklist)
+ return 0;
+
+ for (chunk = chunklist->first; chunk != NULL; chunk = chunk->next) {
+ if (unlink(chunk->name)<0) {
+ if (verbose)
+ printf(_("holding_file_unlink: could not unlink %s: %s\n"),
+ chunk->name, strerror(errno));
+ return 0;
+ }
+ }
- getcwd(current_dir, 999);
+ return 1;
+}
- holding_list = new_sl();
+filetype_t
+holding_file_read_header(
+ char * fname,
+ char ** hostname,
+ char ** diskname,
+ int * level,
+ char ** datestamp)
+{
+ dumpfile_t file;
- if(dateargs) {
- int ok;
+ if (hostname) *hostname = NULL;
+ if (diskname) *diskname = NULL;
+ if (datestamp) *datestamp = NULL;
- date_list = pick_all_datestamp(verbose);
- for(date = date_list->first; date != NULL;) {
- next_date = date->next;
- ok = 0;
- for(datearg=dateargs->first; datearg != NULL && ok==0;
- datearg = datearg->next) {
- ok = match_datestamp(datearg->name, date->name);
- }
- if(ok == 0) { /* remove dir */
- remove_sl(date_list, date);
- }
- date = next_date;
- }
- }
- else if (amflush) {
- date_list = pick_datestamp(verbose);
- }
- else {
- date_list = pick_all_datestamp(verbose);
+ if (!holding_file_get_dumpfile(fname, &file)) {
+ return F_UNKNOWN;
}
- for(date = date_list->first; date !=NULL; date = date->next) {
- if(!datestamp || strcmp(datestamp,date->name) != 0) {
- for(hdisk = getconf_holdingdisks(); hdisk != NULL;
- hdisk = hdisk->next) {
- holding_list = scan_holdingdir(holding_list, hdisk, date->name);
- }
- }
+ if(file.type != F_DUMPFILE && file.type != F_CONT_DUMPFILE) {
+ return file.type;
}
- free_sl(date_list);
- date_list = NULL;
- chdir(current_dir);
- return(holding_list);
+ if (hostname) *hostname = stralloc(file.name);
+ if (diskname) *diskname = stralloc(file.disk);
+ if (level) *level = file.dumplevel;
+ if (datestamp) *datestamp = stralloc(file.datestamp);
+
+ return file.type;
}
-sl_t *pick_all_datestamp(verbose)
-int verbose;
+int
+holding_file_get_dumpfile(
+ char * fname,
+ dumpfile_t *file)
{
- sl_t *holding_list = NULL;
- holdingdisk_t *hdisk;
+ char buffer[DISK_BLOCK_BYTES];
+ int fd;
- holding_list = new_sl();
- for(hdisk = getconf_holdingdisks(); hdisk != NULL; hdisk = hdisk->next)
- holding_list = scan_holdingdisk(holding_list, hdisk->diskdir, verbose);
+ memset(buffer, 0, sizeof(buffer));
- return holding_list;
+ fh_init(file);
+ file->type = F_UNKNOWN;
+ if((fd = open(fname, O_RDONLY)) == -1)
+ return 0;
+
+ if(fullread(fd, buffer, SIZEOF(buffer)) != (ssize_t)sizeof(buffer)) {
+ aclose(fd);
+ return 0;
+ }
+ aclose(fd);
+
+ parse_file_header(buffer, file, SIZEOF(buffer));
+ return 1;
}
+/*
+ * Interactive functions
+ */
+
+sl_t *
+pick_all_datestamp(
+ int v)
+{
+ int old_verbose = holding_set_verbosity(v);
+ sl_t *rv;
+
+ /* get all holding directories, without full paths -- this
+ * will be datestamps only */
+ rv = holding_get_directories(NULL, NULL, 0);
+
+ holding_set_verbosity(old_verbose);
+ return rv;
+}
-sl_t *pick_datestamp(verbose)
-int verbose;
+sl_t *
+pick_datestamp(
+ int verbose)
{
sl_t *holding_list;
sl_t *r_holding_list = NULL;
char **directories = NULL;
int i;
char *answer = NULL;
- char *a;
- int ch;
+ char *a = NULL;
+ int ch = 0;
char max_char = '\0', chupper = '\0';
holding_list = pick_all_datestamp(verbose);
return holding_list;
}
else {
- directories = alloc((holding_list->nb_element) * sizeof(char *));
+ directories = alloc((holding_list->nb_element) * SIZEOF(char *));
for(dir = holding_list->first, i=0; dir != NULL; dir = dir->next,i++) {
directories[i] = dir->name;
}
while(1) {
- puts("\nMultiple Amanda directories, please pick one by letter:");
+ puts(_("\nMultiple Amanda directories, please pick one by letter:"));
for(dir = holding_list->first, max_char = 'A';
dir != NULL && max_char <= 'Z';
dir = dir->next, max_char++) {
printf(" %c. %s\n", max_char, dir->name);
}
max_char--;
- printf("Select directories to flush [A..%c]: [ALL] ", max_char);
+ printf(_("Select directories to flush [A..%c]: [ALL] "), max_char);
fflush(stdout); fflush(stderr);
amfree(answer);
if ((answer = agets(stdin)) == NULL) {
clearerr(stdin);
continue;
}
- a = answer;
- while ((ch = *a++) != '\0' && isspace(ch)) {}
- if(ch == '\0' || strncasecmp(a, "ALL", 3) == 0) {
+
+ if (*answer == '\0' || strncasecmp(answer, "ALL", 3) == 0) {
break;
}
+
+ a = answer;
+ while ((ch = *a++) != '\0') {
+ if (!isspace(ch))
+ break;
+ }
+
do {
if (isspace(ch) || ch == ',') {
continue;
}
- chupper = toupper(ch);
+ chupper = (char)toupper(ch);
if (chupper < 'A' || chupper > max_char) {
free_sl(r_holding_list);
r_holding_list = NULL;
return holding_list;
}
+/*
+ * Application support
+ */
-filetype_t get_amanda_names(fname, hostname, diskname, level)
-char *fname, **hostname, **diskname;
-int *level;
-{
- dumpfile_t file;
- char buffer[DISK_BLOCK_BYTES];
- int fd;
- *hostname = *diskname = NULL;
-
- if((fd = open(fname, O_RDONLY)) == -1)
- return F_UNKNOWN;
-
- if(fullread(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
- aclose(fd);
- return F_UNKNOWN;
- }
- aclose(fd);
-
- parse_file_header(buffer,&file,sizeof(buffer));
- if(file.type != F_DUMPFILE && file.type != F_CONT_DUMPFILE) {
- return file.type;
- }
- *hostname = stralloc(file.name);
- *diskname = stralloc(file.disk);
- *level = file.dumplevel;
-
- return file.type;
-}
-
-
-void get_dumpfile(fname, file)
-char *fname;
-dumpfile_t *file;
-{
- char buffer[DISK_BLOCK_BYTES];
- int fd;
-
- fh_init(file);
- file->type = F_UNKNOWN;
- if((fd = open(fname, O_RDONLY)) == -1)
- return;
-
- if(fullread(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
- aclose(fd);
- return;
- }
- aclose(fd);
-
- parse_file_header(buffer,file,sizeof(buffer));
- return;
-}
-
-
-long size_holding_files(holding_file)
-char *holding_file;
-{
- int fd;
- int buflen;
- char buffer[DISK_BLOCK_BYTES];
- dumpfile_t file;
- char *filename;
- long size=0;
- struct stat finfo;
-
- filename = stralloc(holding_file);
- while(filename != NULL && filename[0] != '\0') {
- if((fd = open(filename,O_RDONLY)) == -1) {
- fprintf(stderr,"size_holding_files: open of %s failed: %s\n",filename,strerror(errno));
- amfree(filename);
- return -1;
- }
- buflen = fullread(fd, buffer, sizeof(buffer));
- parse_file_header(buffer, &file, buflen);
- close(fd);
- if(stat(filename, &finfo) == -1) {
- printf("stat %s: %s\n", filename, strerror(errno));
- finfo.st_size = 0;
- }
- size += (finfo.st_size+1023)/1024;
- filename = newstralloc(filename, file.cont_filename);
- }
- amfree(filename);
- return size;
-}
-
-
-int unlink_holding_files( holding_file )
-char *holding_file;
-{
- int fd;
- int buflen;
- char buffer[DISK_BLOCK_BYTES];
- dumpfile_t file;
- char *filename;
-
- filename = stralloc(holding_file);
- while(filename != NULL && filename[0] != '\0') {
- if((fd = open(filename,O_RDONLY)) == -1) {
- fprintf(stderr,"unlink_holding_files: open of %s failed: %s\n",filename,strerror(errno));
- amfree(filename);
- return 0;
- }
- buflen = fullread(fd, buffer, sizeof(buffer));
- parse_file_header(buffer, &file, buflen);
- close(fd);
- unlink(filename);
- filename = newstralloc(filename,file.cont_filename);
- }
- amfree(filename);
- return 1;
-}
-
-
-int rename_tmp_holding( holding_file, complete )
-char *holding_file;
-int complete;
+int
+rename_tmp_holding(
+ char * holding_file,
+ int complete)
{
int fd;
- int buflen;
+ ssize_t buflen;
char buffer[DISK_BLOCK_BYTES];
dumpfile_t file;
char *filename;
char *filename_tmp = NULL;
+ memset(buffer, 0, sizeof(buffer));
filename = stralloc(holding_file);
while(filename != NULL && filename[0] != '\0') {
filename_tmp = newvstralloc(filename_tmp, filename, ".tmp", NULL);
if((fd = open(filename_tmp,O_RDONLY)) == -1) {
- fprintf(stderr,"rename_tmp_holding: open of %s failed: %s\n",filename_tmp,strerror(errno));
+ fprintf(stderr,_("rename_tmp_holding: open of %s failed: %s\n"),filename_tmp,strerror(errno));
amfree(filename);
amfree(filename_tmp);
return 0;
}
- buflen = fullread(fd, buffer, sizeof(buffer));
+ buflen = fullread(fd, buffer, SIZEOF(buffer));
close(fd);
if(rename(filename_tmp, filename) != 0) {
fprintf(stderr,
- "rename_tmp_holding: could not rename \"%s\" to \"%s\": %s",
+ _("rename_tmp_holding: could not rename \"%s\" to \"%s\": %s"),
filename_tmp, filename, strerror(errno));
}
- if (buflen == 0) {
- fprintf(stderr,"rename_tmp_holding: %s: empty file?\n", filename);
+ if (buflen <= 0) {
+ fprintf(stderr,_("rename_tmp_holding: %s: empty file?\n"), filename);
amfree(filename);
amfree(filename_tmp);
return 0;
}
- parse_file_header(buffer, &file, buflen);
+ parse_file_header(buffer, &file, (size_t)buflen);
if(complete == 0 ) {
if((fd = open(filename, O_RDWR)) == -1) {
- fprintf(stderr, "rename_tmp_holdingX: open of %s failed: %s\n",
+ fprintf(stderr, _("rename_tmp_holdingX: open of %s failed: %s\n"),
filename, strerror(errno));
amfree(filename);
amfree(filename_tmp);
}
file.is_partial = 1;
- build_header(buffer, &file, sizeof(buffer));
- fullwrite(fd, buffer, sizeof(buffer));
+ build_header(buffer, &file, SIZEOF(buffer));
+ fullwrite(fd, buffer, SIZEOF(buffer));
close(fd);
}
filename = newstralloc(filename, file.cont_filename);
return 1;
}
-
-void cleanup_holdingdisk(diskdir, verbose)
-char *diskdir;
-int verbose;
+void
+cleanup_holdingdisk(
+ char * diskdir,
+ int verbose)
{
DIR *topdir;
struct dirent *workdir;
if((topdir = opendir(diskdir)) == NULL) {
if(verbose && errno != ENOENT)
- printf("Warning: could not open holding dir %s: %s\n",
+ printf(_("Warning: could not open holding dir %s: %s\n"),
diskdir, strerror(errno));
return;
}
/* find all directories of the right format */
if(verbose)
- printf("Scanning %s...\n", diskdir);
- chdir(diskdir);
+ printf(_("Scanning %s...\n"), diskdir);
+ if ((chdir(diskdir)) == -1) {
+ log_add(L_INFO, _("%s: could not chdir: %s"),
+ diskdir, strerror(errno));
+ }
while((workdir = readdir(topdir)) != NULL) {
- if(is_dot_or_dotdot(workdir->d_name)
- || strcmp(workdir->d_name, "lost+found") == 0) {
+ if(strcmp(workdir->d_name, ".") == 0
+ || strcmp(workdir->d_name, "..") == 0
+ || strcmp(workdir->d_name, "lost+found") == 0)
continue;
- }
+
if(verbose)
printf(" %s: ", workdir->d_name);
if(!is_dir(workdir->d_name)) {
if(verbose)
- puts("skipping cruft file, perhaps you should delete it.");
+ puts(_("skipping cruft file, perhaps you should delete it."));
}
else if(!is_datestr(workdir->d_name)) {
- if(verbose)
- puts("skipping cruft directory, perhaps you should delete it.");
+ if(verbose && (strcmp(workdir->d_name, "lost+found")!=0) )
+ puts(_("skipping cruft directory, perhaps you should delete it."));
}
else if(rmdir(workdir->d_name) == 0) {
if(verbose)
- puts("deleted empty Amanda directory.");
+ puts(_("deleted empty Amanda directory."));
}
}
closedir(topdir);
}
-int mkholdingdir(diskdir)
-char *diskdir;
+int
+mkholdingdir(
+ char * diskdir)
{
struct stat stat_hdp;
int success = 1;
if (mkpdir(diskdir, 0770, (uid_t)-1, (gid_t)-1) != 0 && errno != EEXIST) {
- log_add(L_WARNING, "WARNING: could not create parents of %s: %s",
+ log_add(L_WARNING, _("WARNING: could not create parents of %s: %s"),
diskdir, strerror(errno));
success = 0;
}
else if (mkdir(diskdir, 0770) != 0 && errno != EEXIST) {
- log_add(L_WARNING, "WARNING: could not create %s: %s",
+ log_add(L_WARNING, _("WARNING: could not create %s: %s"),
diskdir, strerror(errno));
success = 0;
}
else if (stat(diskdir, &stat_hdp) == -1) {
- log_add(L_WARNING, "WARNING: could not stat %s: %s",
+ log_add(L_WARNING, _("WARNING: could not stat %s: %s"),
diskdir, strerror(errno));
success = 0;
}
else {
if (!S_ISDIR((stat_hdp.st_mode))) {
- log_add(L_WARNING, "WARNING: %s is not a directory",
+ log_add(L_WARNING, _("WARNING: %s is not a directory"),
diskdir);
success = 0;
}
else if (access(diskdir,W_OK) != 0) {
- log_add(L_WARNING, "WARNING: directory %s is not writable",
+ log_add(L_WARNING, _("WARNING: directory %s is not writable"),
diskdir);
success = 0;
}