YARN-3089. LinuxContainerExecutor does not handle file arguments to deleteAsUser. Contributed by Eric Payne

This commit is contained in:
Jason Lowe 2015-02-06 20:39:01 +00:00
parent c1957fef29
commit 4c484320b4
3 changed files with 45 additions and 5 deletions

View File

@ -504,6 +504,9 @@ Release 2.7.0 - UNRELEASED
YARN-2694. Ensure only single node label specified in ResourceRequest.
(Wangda Tan via jianhe)
YARN-3089. LinuxContainerExecutor does not handle file arguments to
deleteAsUser (Eric Payne via jlowe)
Release 2.6.0 - 2014-11-18
INCOMPATIBLE CHANGES

View File

@ -1354,21 +1354,37 @@ int delete_as_user(const char *user,
const char *subdir,
char* const* baseDirs) {
int ret = 0;
int subDirEmptyStr = (subdir == NULL || subdir[0] == 0);
int needs_tt_user = subDirEmptyStr;
char** ptr;
// TODO: No switching user? !!!!
if (baseDirs == NULL || *baseDirs == NULL) {
return delete_path(subdir, strlen(subdir) == 0);
return delete_path(subdir, needs_tt_user);
}
// do the delete
for(ptr = (char**)baseDirs; *ptr != NULL; ++ptr) {
char* full_path = concatenate("%s/%s", "user subdir", 2,
*ptr, subdir);
char* full_path = NULL;
struct stat sb;
if (stat(*ptr, &sb) != 0) {
fprintf(LOGFILE, "Could not stat %s\n", *ptr);
return -1;
}
if (!S_ISDIR(sb.st_mode)) {
if (!subDirEmptyStr) {
fprintf(LOGFILE, "baseDir \"%s\" is a file and cannot contain subdir \"%s\".\n", *ptr, subdir);
return -1;
}
full_path = strdup(*ptr);
needs_tt_user = 0;
} else {
full_path = concatenate("%s/%s", "user subdir", 2, *ptr, subdir);
}
if (full_path == NULL) {
return -1;
}
int this_ret = delete_path(full_path, strlen(subdir) == 0);
int this_ret = delete_path(full_path, needs_tt_user);
free(full_path);
// delete as much as we can, but remember the error
if (this_ret != 0) {

View File

@ -382,7 +382,28 @@ void test_delete_user() {
if (mkdirs(app_dir, 0700) != 0) {
exit(1);
}
char buffer[100000];
sprintf(buffer, "%s/test.cfg", app_dir);
if (write_config_file(buffer) != 0) {
exit(1);
}
char * dirs[] = {buffer, 0};
int ret = delete_as_user(yarn_username, "file1" , dirs);
if (ret == 0) {
printf("FAIL: if baseDir is a file, delete_as_user should fail if a subdir is also passed\n");
exit(1);
}
// Pass a file to delete_as_user in the baseDirs parameter. The file should
// be deleted.
ret = delete_as_user(yarn_username, "" , dirs);
if (ret != 0) {
printf("FAIL: delete_as_user could not delete baseDir when baseDir is a file: return code is %d\n", ret);
exit(1);
}
sprintf(buffer, "%s/local-1/usercache/%s", TEST_ROOT, yarn_username);
if (access(buffer, R_OK) != 0) {
printf("FAIL: directory missing before test\n");