File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -403,27 +403,29 @@ hdfs_command(
403403 break ;
404404 case GLOBUS_GFS_CMD_RMD :
405405{
406- int numEntries = 0 ;
406+ int numEntries = -1 ;
407407 errno = 0 ;
408408 hdfsFileInfo * info = hdfsListDirectory (hdfs_handle -> fs , PathName , & numEntries );
409- if (numEntries ) { // NOTE: above call sets info to NULL in case of empty directory.
410- errno = ENOTEMPTY ;
411- SystemError (hdfs_handle , "rmdir" , result );
412- }
413409 if (info ) {
414410 hdfsFreeFileInfo (info , numEntries );
415411 info = NULL ;
416- } else if (errno != ENOENT ) {
412+ errno = 0 ;
413+ }
414+ if (numEntries > 0 ) { // NOTE: above call sets info to NULL in case of empty directory.
415+ errno = ENOTEMPTY ;
416+ SystemError (hdfs_handle , "rmdir" , result );
417+ break ;
418+ }
419+ if ((numEntries < 0 ) && (errno != ENOENT )) {
417420 if (errno ) {
418421 SystemError (hdfs_handle , "rmdir" , result );
419- } else {
422+ } else { // Logic error in libhdfs: didn't set numEntries or errno.
420423 GenericError (hdfs_handle , "Unable to delete directory (reason unknown)" , result );
421424 }
422425 break ;
423426 }
424- if (numEntries ) {break ;}
425427}
426- // Not done - fall through
428+ // Only case remaining is empty directory. OK to delete; not done - fall through
427429 case GLOBUS_GFS_CMD_DELE :
428430{
429431 errno = 0 ;
Original file line number Diff line number Diff line change @@ -101,11 +101,13 @@ hdfs_stat(
101101 else
102102 {
103103 int i ;
104-
104+
105+ stat_count = -1 ; // Workaround for HDFS-8407: hdfsListDirectory doesn't set errno=0 on success.
106+ errno = 0 ;
105107 hdfsFileInfo * dir = hdfsListDirectory (hdfs_handle -> fs , PathName , & stat_count );
106108 if (dir == NULL )
107109 {
108- if (errno == 0 )
110+ if (! stat_count ) // On success, stat_count is updated.
109111 { // Empty directory case
110112 stat_array = (globus_gfs_stat_t * ) globus_malloc (sizeof (globus_gfs_stat_t ));
111113 if (!stat_array )
You can’t perform that action at this time.
0 commit comments