Whamcloud - gitweb
LU-4569 hsm: Prevent copytool from importing existing file.
[fs/lustre-release.git] / lustre / utils / lhsmtool_posix.c
index 91ec7b5..8c8ac00 100644 (file)
@@ -1392,10 +1392,20 @@ static char *path_concat(const char *dirname, const char *basename)
 
 static int ct_import_fid(const lustre_fid *import_fid)
 {
-       char fid_path[PATH_MAX];
+       char    fid_path[PATH_MAX];
+       int     rc;
+
+       ct_path_lustre(fid_path, sizeof(fid_path), opt.o_mnt, import_fid);
+       rc = access(fid_path, F_OK);
+       if (rc == 0 || errno != ENOENT) {
+               rc = (errno == 0) ? -EEXIST : -errno;
+               CT_ERROR(rc, "cannot import '"DFID"'", PFID(import_fid));
+               return rc;
+       }
 
        ct_path_archive(fid_path, sizeof(fid_path), opt.o_hsm_root,
                        import_fid);
+
        CT_TRACE("Resolving "DFID" to %s", PFID(import_fid), fid_path);
 
        return ct_import_one(fid_path, opt.o_dst);
@@ -1776,7 +1786,8 @@ static int ct_run(void)
                         hal->hal_fsname, hal->hal_archive_id, hal->hal_count);
 
                if (strcmp(hal->hal_fsname, fs_name) != 0) {
-                       CT_ERROR(EINVAL, "'%s' invalid fs name, expecting: %s",
+                       rc = -EINVAL;
+                       CT_ERROR(rc, "'%s' invalid fs name, expecting: %s",
                                 hal->hal_fsname, fs_name);
                        err_major++;
                        if (opt.o_abort_on_error)