Beispiel #1
0
bool set_attributes(const char *path, char cmd, struct stat *statp, int64_t winattr, struct cntr *cntr)
{
   struct utimbuf ut;
   bool ok = true;
 
   ut.actime = statp->st_atime;
   ut.modtime = statp->st_mtime;

#ifdef HAVE_WIN32
	win32_chmod(path, statp->st_mode, winattr);
	set_file_times(path, &ut, statp, cntr);
	return true;
#endif

   /* ***FIXME**** optimize -- don't do if already correct */
   /*
    * For link, change owner of link using lchown, but don't
    *   try to do a chmod as that will update the file behind it.
    */

   /* watch out, a metadata restore will have cmd set to CMD_METADATA or
      CMD_ENC_META, but that is OK at the moment because we are not doing
      meta stuff on links. */
   if (cmd==CMD_SOFT_LINK) {
      /* Change owner of link, not of real file */
      if (lchown(path, statp->st_uid, statp->st_gid) < 0) {
         berrno be;
         logw(cntr, "Unable to set file owner %s: ERR=%s",
            path, be.bstrerror());
         ok = false;
      }
   } else {
      if (chown(path, statp->st_uid, statp->st_gid) < 0) {
         berrno be;
         logw(cntr, "Unable to set file owner %s: ERR=%s",
            path, be.bstrerror());
         ok = false;
      }
      if (chmod(path, statp->st_mode) < 0) {
         berrno be;
         logw(cntr, "Unable to set file modes %s: ERR=%s",
            path, be.bstrerror());
         ok = false;
      }

      if(set_file_times(path, &ut, statp, cntr)) ok=false;
#ifdef HAVE_CHFLAGS
      /*
       * FreeBSD user flags
       *
       * Note, this should really be done before the utime() above,
       *  but if the immutable bit is set, it will make the utimes()
       *  fail.
       */
      if (chflags(path, statp->st_flags) < 0) {
         berrno be;
         logw(cntr, "Unable to set file flags %s: ERR=%s",
            path, be.bstrerror());
         ok = false;
      }
#endif
   }

   return ok;
}
Beispiel #2
0
int attribs_set(struct asfd *asfd, const char *path,
	struct stat *statp, uint64_t winattr, struct conf *conf)
{
	struct utimbuf ut;

	ut.actime=statp->st_atime;
	ut.modtime=statp->st_mtime;

#ifdef HAVE_WIN32
	win32_chmod(path, statp->st_mode, winattr);
	set_file_times(asfd, path, &ut, statp, conf);
	return 0;
#endif

	/* ***FIXME**** optimize -- don't do if already correct */
	/*
	 * For link, change owner of link using lchown, but don't
	 *   try to do a chmod as that will update the file behind it.
	 */

	/* Watch out, a metadata restore will have cmd set to CMD_METADATA or
	   CMD_ENC_META, but that is OK at the moment because we are not doing
	   meta stuff on links. */
	if(S_ISLNK(statp->st_mode))
	{
		// Change owner of link, not of real file.
		if(lchown(path, statp->st_uid, statp->st_gid)<0)
		{
			berrno be;
			berrno_init(&be);
			logw(asfd, conf, "Unable to set file owner %s: ERR=%s",
				path, berrno_bstrerror(&be, errno));
			return -1;
		}
	}
	else
	{
		if(chown(path, statp->st_uid, statp->st_gid)<0)
		{
			berrno be;
			berrno_init(&be);
			logw(asfd, conf, "Unable to set file owner %s: ERR=%s",
				path, berrno_bstrerror(&be, errno));
			return -1;
		}
		if(chmod(path, statp->st_mode) < 0)
		{
			berrno be;
			berrno_init(&be);
			logw(asfd, conf, "Unable to set file modes %s: ERR=%s",
				path, berrno_bstrerror(&be, errno));
			return -1;
		}

		if(set_file_times(asfd, path, &ut, statp, conf))
			return -1;
#ifdef HAVE_CHFLAGS
		/*
		 * FreeBSD user flags
		 *
		 * Note, this should really be done before the utime() above,
		 *  but if the immutable bit is set, it will make the utimes()
		 *  fail.
		 */
		if(chflags(path, statp->st_flags)<0)
		{
			berrno be;
			berrno_init(&be);
			logw(conf, "Unable to set file flags %s: ERR=%s",
				path, berrno_bstrerror(&be, errno));
			return -1;
		}
#endif
	}

	return 0;
}
Beispiel #3
0
int attribs_set(struct asfd *asfd, const char *path,
                struct stat *statp, uint64_t winattr, struct cntr *cntr)
{
    struct utimbuf ut;

    ut.actime=statp->st_atime;
    ut.modtime=statp->st_mtime;

#ifdef HAVE_WIN32
    win32_chmod(path, statp->st_mode, winattr);
    set_file_times(asfd, path, &ut, statp, cntr);
    return 0;
#endif

    if(lchown(path, statp->st_uid, statp->st_gid)<0)
    {
        berrno be;
        berrno_init(&be);
        logw(asfd, cntr, "Unable to set file owner %s: ERR=%s\n",
             path, berrno_bstrerror(&be, errno));
        return -1;
    }

    /* Watch out, a metadata restore will have cmd set to CMD_METADATA or
       CMD_ENC_META, but that is OK at the moment because we are not doing
       meta stuff on links. */
    if(S_ISLNK(statp->st_mode))
    {
#ifdef HAVE_LUTIMES
        if(do_lutimes(path, statp)) {
            berrno be;
            berrno_init(&be);
            logw(asfd, cntr, "Unable to set lutimes %s: ERR=%s\n",
                 path, berrno_bstrerror(&be, errno));
            return -1;
        }
#endif
    }
    else
    {
        if(chmod(path, statp->st_mode) < 0)
        {
            berrno be;
            berrno_init(&be);
            logw(asfd, cntr,
                 "Unable to set file modes %s: ERR=%s\n",
                 path, berrno_bstrerror(&be, errno));
            return -1;
        }

        if(set_file_times(asfd, path, &ut, statp, cntr))
            return -1;
#ifdef HAVE_CHFLAGS
        /*
         * FreeBSD user flags
         *
         * Note, this should really be done before the utime() above,
         *  but if the immutable bit is set, it will make the utimes()
         *  fail.
         */
        if(chflags(path, statp->st_flags)<0)
        {
            berrno be;
            berrno_init(&be);
            logw(asfd, cntr,
                 "Unable to set file flags %s: ERR=%s\n",
                 path, berrno_bstrerror(&be, errno));
            return -1;
        }
#endif
    }

    return 0;
}