Skip to content

Commit b734a95

Browse files
committed
Merge pull request #2 from bbockelm/implement_rename
Fix rename and rmdir for LIGO support.
2 parents 8fe65ee + 825b19c commit b734a95

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

src/gridftp_hdfs.c

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/gridftp_hdfs_error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
char * path = hdfs_handle ? hdfs_handle->pathname : NULL; \
99
char * host = hdfs_handle ? hdfs_handle->local_host : NULL; \
1010
snprintf(formatted_msg, MESSAGE_BUFFER_SIZE, "%s (host=%s, user=%s, path=%s)", msg, host, user, path); \
11+
formatted_msg[MESSAGE_BUFFER_SIZE-1] = '\0'; \
1112
globus_gfs_log_message(GLOBUS_GFS_LOG_ERR, "%s\n", formatted_msg);
1213

1314

0 commit comments

Comments
 (0)