Exemplo n.º 1
0
int check_infofile(
    char        *infodir,
    disklist_t  *dl,
    char       **errmsg)
{
    disk_t      *dp, *diskp;
    char        *hostinfodir, *old_hostinfodir, *Xhostinfodir;
    char        *diskdir,     *old_diskdir,     *Xdiskdir;
    char        *infofile,    *old_infofile,    *Xinfofile;
    struct stat  statbuf;
    int other_dle_match;

    if (stat(infodir, &statbuf) != 0) {
	return 0;
    }

    for (dp = dl->head; dp != NULL; dp = dp->next) {
	hostinfodir = sanitise_filename(dp->host->hostname);
	diskdir     = sanitise_filename(dp->name);
	infofile = vstralloc(infodir, "/", hostinfodir, "/", diskdir,
			     "/info", NULL);
	if (stat(infofile, &statbuf) == -1 && errno == ENOENT) {
	    old_hostinfodir = old_sanitise_filename(dp->host->hostname);
	    old_diskdir     = old_sanitise_filename(dp->name);
	    old_infofile    = vstralloc(infodir, old_hostinfodir, "/",
					old_diskdir, "/info", NULL);
	    if (stat(old_infofile, &statbuf) == 0) {
		other_dle_match = 0;
		diskp = dl->head;
		while (diskp != NULL) {
		    Xhostinfodir = sanitise_filename(diskp->host->hostname);
		    Xdiskdir     = sanitise_filename(diskp->name);
		    Xinfofile = vstralloc(infodir, "/", Xhostinfodir, "/",
					  Xdiskdir, "/info", NULL);
		    if (strcmp(old_infofile, Xinfofile) == 0) {
			other_dle_match = 1;
			diskp = NULL;
		    }
		    else {
			diskp = diskp->next;
		    }
		}
		if (other_dle_match == 0) {
		    if(mkpdir(infofile, (mode_t)0755, (uid_t)-1,
			      (gid_t)-1) == -1) {
			*errmsg = vstralloc("Can't create directory for ",
					    infofile, NULL);
			return -1;
		    }
		    if(copy_file(infofile, old_infofile, errmsg) == -1) 
			return -1;
		}
	    }
	}
	amfree(diskdir);
	amfree(hostinfodir);
	amfree(infofile);
    }
    return 0;
}
Exemplo n.º 2
0
char *
getoldindexfname(
    char *	host,
    char *	disk,
    char *	date,
    int		level)
{
  char *conf_indexdir;
  char *buf;
  char level_str[NUM_STR_SIZE];
  char datebuf[14 + 1];
  char *dc = NULL;
  char *pc;
  int ch;

  if (date != NULL) {
    dc = date;
    pc = datebuf;
    while (pc < datebuf + sizeof(datebuf)) {
      ch = *dc++;
      *pc++ = (char)ch;
      if (ch == '\0') {
        break;
      } else if (! isdigit (ch)) {
        pc--;
      }
    }
    datebuf[sizeof(datebuf)-1] = '\0';
    dc = datebuf;

    g_snprintf(level_str, sizeof(level_str), "%d", level);
  }

  host = old_sanitise_filename(host);
  if (disk != NULL) {
    disk = old_sanitise_filename(disk);
  }

  conf_indexdir = config_dir_relative(getconf_str(CNF_INDEXDIR));
  /*
   * Note: g_strjoin(NULL, ) will stop at the first NULL, which might be
   * "disk" or "dc" (datebuf) rather than the full file name.
   */
  buf = g_strjoin(NULL, conf_indexdir, "/",
		  host, "/",
		  disk, "/",
		  dc, "_",
		  level_str, COMPRESS_SUFFIX,
		  NULL);

  amfree(conf_indexdir);
  amfree(host);
  amfree(disk);

  return buf;
}
Exemplo n.º 3
0
int check_infofile(
    char        *infodir,
    disklist_t  *dl,
    char       **errmsg)
{
    GList       *dlist, *dlist1;
    disk_t      *dp, *diskp;
    char        *hostinfodir, *old_hostinfodir;
    char        *diskdir,     *old_diskdir;
    char        *infofile,    *old_infofile;
    struct stat  statbuf;
    int other_dle_match;

    if (stat(infodir, &statbuf) != 0) {
	return 0;
    }

//    for (dp = dl->head; dp != NULL; dp = dp->next) {
    for (dlist = dl->head; dlist != NULL; dlist = dlist->next) {
	dp = dlist->data;
	hostinfodir = sanitise_filename(dp->host->hostname);
	diskdir     = sanitise_filename(dp->name);
	infofile = g_strjoin(NULL, infodir, "/", hostinfodir, "/", diskdir,
			     "/info", NULL);
	if (stat(infofile, &statbuf) == -1 && errno == ENOENT) {
	    old_hostinfodir = old_sanitise_filename(dp->host->hostname);
	    old_diskdir     = old_sanitise_filename(dp->name);
	    old_infofile    = g_strjoin(NULL, infodir, old_hostinfodir, "/",
					old_diskdir, "/info", NULL);
	    if (stat(old_infofile, &statbuf) == 0) {
		other_dle_match = 0;
		dlist1 = dl->head;
		while (dlist1 != NULL) {
		    char *Xhostinfodir;
		    char *Xdiskdir;
		    char *Xinfofile;

		    diskp = dlist1->data;
		    Xhostinfodir = sanitise_filename(diskp->host->hostname);
		    Xdiskdir     = sanitise_filename(diskp->name);
		    Xinfofile = g_strjoin(NULL, infodir, "/", Xhostinfodir, "/",
					  Xdiskdir, "/info", NULL);
		    if (g_str_equal(old_infofile, Xinfofile)) {
			other_dle_match = 1;
			dlist1 = NULL;
		    }
		    else {
			dlist1 = dlist1->next;
		    }
		    amfree(Xhostinfodir);
		    amfree(Xdiskdir);
		    amfree(Xinfofile);
		}
		if (other_dle_match == 0) {
		    if(mkpdir(infofile, (mode_t)0755, (uid_t)-1,
			      (gid_t)-1) == -1) {
			*errmsg = g_strjoin(NULL, "Can't create directory for ",
					    infofile, NULL);
			amfree(hostinfodir);
			amfree(diskdir);
			amfree(infofile);
			amfree(old_hostinfodir);
			amfree(old_diskdir);
			amfree(old_infofile);
			return -1;
		    }
		    if(copy_file(infofile, old_infofile, errmsg) == -1) {
			amfree(hostinfodir);
			amfree(diskdir);
			amfree(infofile);
			amfree(old_hostinfodir);
			amfree(old_diskdir);
			amfree(old_infofile);
			return -1;
		    }
		}
	    }
	    amfree(old_hostinfodir);
	    amfree(old_diskdir);
	    amfree(old_infofile);
	}
	amfree(diskdir);
	amfree(hostinfodir);
	amfree(infofile);
    }
    return 0;
}