diff --git a/rpm/xrootd-hdfs.spec b/rpm/xrootd-hdfs.spec index 5b6d21a..406ce4e 100644 --- a/rpm/xrootd-hdfs.spec +++ b/rpm/xrootd-hdfs.spec @@ -1,5 +1,5 @@ Name: xrootd-hdfs -Version: 2.0.0 +Version: 2.0.1 Release: 1%{?dist} Summary: HDFS plugin for xrootd @@ -65,6 +65,9 @@ rm $RPM_BUILD_ROOT%{_bindir}/xrootd_hdfs_envcheck %{_includedir}/XrdHdfs.hh %changelog +* Thu Mar 08 2018 Brian Bockelman - 2.0.1-1 +- Fix directory creation logic. + * Tue Mar 06 2018 Brian Bockelman - 2.0.0-1 - Add full support for writing files into HDFS. diff --git a/src/XrdHdfs.cc b/src/XrdHdfs.cc index f96f94c..ddd91f5 100644 --- a/src/XrdHdfs.cc +++ b/src/XrdHdfs.cc @@ -35,6 +35,13 @@ #define REUSE_CONNECTION 1 +// Set to 1 to have the mkdir create the directory with the mode requested +// by the user. This has been problematic as XRootD has requested very restrictive (0700) +// mode compared to what is typical for a POSIX directory. +#ifndef MKDIR_PERFORM_CHMOD +#define MKDIR_PERFORM_CHMOD 0 +#endif + // Static copy of filesystem for when we're used by the cmsd. XrdSysMutex XrdHdfsSys::m_fs_mutex; hdfsFS XrdHdfsSys::m_cmsd_fs = NULL; @@ -445,7 +452,7 @@ int XrdHdfsFile::Open(const char *path, // In // Prepare to create or open the file, as needed // if (openMode & O_TRUNC) { - open_flag = O_TRUNC; + open_flag = O_TRUNC | O_WRONLY; } // Setup a new filesystem instance. @@ -979,7 +986,7 @@ XrdHdfsSys::Mkdir(const char *req_path, mode_t mode, int mkpath, if (path[len] == '/') { path[len] = '\0'; } - } while (path[len] != '\0'); + } while (path[len] == '\0'); char *parent_dir = strrchr(path, '/'); if (parent_dir && (parent_dir != path)) { parent_dir++; // Trailing-slash logic above guarantees there @@ -989,7 +996,7 @@ XrdHdfsSys::Mkdir(const char *req_path, mode_t mode, int mkpath, errno = 0; int retval = hdfsExists(fs, path); *parent_dir = old_value; - if (!retval) { + if (retval) { retc = XrdHdfsSys::Emsg(epname, error, errno ? errno : ENOENT, "mkdir", path); goto cleanup; @@ -1003,11 +1010,23 @@ XrdHdfsSys::Mkdir(const char *req_path, mode_t mode, int mkpath, goto cleanup; } - errno = 0; - if (mode && (-1 == hdfsChmod(fs, path, mode))) { - retc = XrdHdfsSys::Emsg(epname, error, errno ? errno : EIO, "chmod", - path); - goto cleanup; + if (MKDIR_PERFORM_CHMOD && mode) { + errno = 0; + hdfsFileInfo *fileInfo = hdfsGetPathInfo(fs, path); + if (NULL == fileInfo) { + retc = XrdHdfsSys::Emsg(epname, error, errno ? errno : ENOENT, + "stat", path); + goto cleanup; + } + mode_t curmode = fileInfo->mPermissions; + hdfsFreeFileInfo(fileInfo, 1); + + errno = 0; + if ((curmode != mode) && (-1 == hdfsChmod(fs, path, mode))) { + retc = XrdHdfsSys::Emsg(epname, error, errno ? errno : EIO, "chmod", + path); + goto cleanup; + } } cleanup: