@@ -372,14 +372,16 @@ hdfs_command(
372372 PathName ++ ;
373373 }
374374
375- GlobusGFSErrorSystemError ("command" , ENOSYS );
375+ errno = ENOSYS ;
376+ hdfs_handle -> pathname = PathName ;
377+ SystemError (hdfs_handle , "command" , result );
376378 switch (cmd_info -> command ) {
377379 case GLOBUS_GFS_CMD_MKD :
378380{
379381 errno = 0 ;
380382 if (hdfsCreateDirectory (hdfs_handle -> fs , PathName ) == -1 ) {
381383 if (errno ) {
382- result = GlobusGFSErrorSystemError ( "mkdir" , errno );
384+ SystemError ( hdfs_handle , "mkdir" , result );
383385 } else {
384386 GenericError (hdfs_handle , "Unable to create directory (reason unknown)" , result );
385387 }
@@ -389,13 +391,34 @@ hdfs_command(
389391}
390392 break ;
391393 case GLOBUS_GFS_CMD_RMD :
392- break ;
394+ {
395+ int numEntries = 0 ;
396+ errno = 0 ;
397+ hdfsFileInfo * info = hdfsListDirectory (hdfs_handle -> fs , PathName , & numEntries );
398+ if (numEntries ) { // NOTE: above call sets info to NULL in case of empty directory.
399+ errno = ENOTEMPTY ;
400+ SystemError (hdfs_handle , "rmdir" , result );
401+ }
402+ if (info ) {
403+ hdfsFreeFileInfo (info , numEntries );
404+ info = NULL ;
405+ } else if (errno != ENOENT ) {
406+ if (errno ) {
407+ SystemError (hdfs_handle , "rmdir" , result );
408+ } else {
409+ GenericError (hdfs_handle , "Unable to delete directory (reason unknown)" , result );
410+ }
411+ break ;
412+ }
413+ if (numEntries ) {break ;}
414+ }
415+ // Not done - fall through
393416 case GLOBUS_GFS_CMD_DELE :
394417{
395418 errno = 0 ;
396419 if (hdfsDelete (hdfs_handle -> fs , PathName , 0 ) == -1 ) {
397420 if (errno ) {
398- result = GlobusGFSErrorSystemError ( "unlink" , errno );
421+ SystemError ( hdfs_handle , "unlink" , result );
399422 } else {
400423 GenericError (hdfs_handle , "Unable to delete file (reason unknown)" , result );
401424 }
@@ -405,6 +428,35 @@ hdfs_command(
405428}
406429 break ;
407430 case GLOBUS_GFS_CMD_RNTO :
431+ {
432+ const char * FromPathName = cmd_info -> from_pathname ;
433+ while (FromPathName [0 ] == '/' && FromPathName [1 ] == '/' )
434+ {
435+ FromPathName ++ ;
436+ }
437+ if (strncmp (FromPathName , hdfs_handle -> mount_point , hdfs_handle -> mount_point_len )== 0 ) {
438+ FromPathName += hdfs_handle -> mount_point_len ;
439+ }
440+ while (FromPathName [0 ] == '/' && FromPathName [1 ] == '/' )
441+ {
442+ FromPathName ++ ;
443+ }
444+
445+ errno = 0 ;
446+ if (hdfsRename (hdfs_handle -> fs , FromPathName , PathName )) {
447+ if (errno ) {
448+ char * rename_msg = (char * )globus_malloc (1024 );
449+ snprintf (rename_msg , 1024 , "rename from %s" , FromPathName );
450+ rename_msg [1023 ] = '\0' ;
451+ SystemError (hdfs_handle , rename_msg , result );
452+ globus_free (rename_msg );
453+ } else {
454+ GenericError (hdfs_handle , "Unable to rename file (reason unknown)" , result );
455+ }
456+ } else {
457+ result = GLOBUS_SUCCESS ;
458+ }
459+ }
408460 break ;
409461 case GLOBUS_GFS_CMD_RNFR :
410462 break ;
0 commit comments