Exemplo n.º 1
0
int remove_project_dir(PROJECT& p) {
    char buf[1024];
    int retval;

    get_project_dir(&p, buf, sizeof(buf));
    retval = client_clean_out_dir(buf, "remove project dir");
    if (retval) {
        msg_printf(&p, MSG_INTERNAL_ERROR, "Can't delete file %s", boinc_failed_file);
        return retval;
    }
    return remove_project_owned_dir(buf);
}
Exemplo n.º 2
0
// recursively delete everything in the specified directory
// (but not the directory itself).
// If an error occurs, delete as much as possible.
//
int client_clean_out_dir(
    const char* dirpath, const char* reason, const char* except
) {
    char filename[MAXPATHLEN], path[MAXPATHLEN];
    int retval, final_retval = 0;
    DIRREF dirp;

    if (reason && log_flags.slot_debug) {
        msg_printf(0, MSG_INFO, "[slot] cleaning out %s: %s", dirpath, reason);
    }
    dirp = dir_open(dirpath);
    if (!dirp) {
#ifndef _WIN32
        if (g_use_sandbox && (errno == EACCES)) {
            // dir may be owned by boinc_apps
            return remove_project_owned_file_or_dir(dirpath);
        }
#endif
        return 0;    // if dir doesn't exist, it's empty
    }

    while (1) {
        safe_strcpy(filename, "");
        retval = dir_scan(filename, dirp, sizeof(filename));
        if (retval) {
            if (retval != ERR_NOT_FOUND) {
                if (log_flags.slot_debug) {
                    msg_printf(0, MSG_INFO,
                        "[slot] dir_scan(%s) failed: %s",
                        dirpath, boincerror(retval)
                    );
                }
                final_retval = retval;
            }
            break;
        }
        if (except && !strcmp(except, filename)) {
            continue;
        }
        snprintf(path, sizeof(path), "%s/%s", dirpath,  filename);
        if (is_dir(path)) {
            retval = client_clean_out_dir(path, NULL);
            if (retval) final_retval = retval;
            retval = remove_project_owned_dir(path);
            if (retval) final_retval = retval;
        } else {
            retval = delete_project_owned_file(path, false);
            if (retval) final_retval = retval;
        }
    }
    dir_close(dirp);
    return final_retval;
}
Exemplo n.º 3
0
/// Recursively delete everything in the specified directory.
/// (but not the directory itself).
/// If an error occurs, delete as much as possible.
///
/// \param[in] dirpath Path to the directory that should be cleared.
/// \return Zero on success, nonzero otherwise.
int client_clean_out_dir(const char* dirpath) {
    int final_retval = 0;
    DIRREF dirp;

    dirp = dir_open(dirpath);
    if (!dirp) {
#ifndef _WIN32
        if (g_use_sandbox && (errno == EACCES)) {
            // dir may be owned by boinc_apps
            return remove_project_owned_file_or_dir(dirpath);
        }
#endif
        return 0;    // if dir doesn't exist, it's empty
    }

    while (true) {
        std::string filename;
        if (dir_scan(filename, dirp)) {
            break;
        }
        std::string path(dirpath);
        path.append("/").append(filename);

        int retval;
        if (is_dir(path.c_str())) {
            retval = client_clean_out_dir(path.c_str());
            if (retval) {
                final_retval = retval;
            }
            retval = remove_project_owned_dir(path.c_str());
            if (retval) {
                final_retval = retval;
            }
        } else {
            retval = delete_project_owned_file(path.c_str(), false);
            if (retval) {
                final_retval = retval;
            }
        }
    }
    dir_close(dirp);
    return final_retval;
}
Exemplo n.º 4
0
// delete unused stuff in the slots/ directory
//
void delete_old_slot_dirs() {
    char filename[1024], path[MAXPATHLEN];
    DIRREF dirp;
    int retval;

    dirp = dir_open(SLOTS_DIR);
    if (!dirp) return;
    while (1) {
        strcpy(filename, "");
        retval = dir_scan(filename, dirp, sizeof(filename));
        if (retval) break;
        snprintf(path, sizeof(path), "%s/%s", SLOTS_DIR, filename);
        if (is_dir(path)) {
#ifndef _WIN32
#if HAVE_SYS_SHM_H
            char init_data_path[MAXPATHLEN];
            SHMEM_SEG_NAME shmem_seg_name;

            // If BOINC crashes or exits suddenly (e.g., due to
            // being called with --exit_after_finish) it may leave
            // orphan shared memory segments in the system.
            // Clean these up here. (We must do this before deleting the
            // INIT_DATA_FILE, if any, from each slot directory.)
            //
            snprintf(init_data_path, sizeof(init_data_path), "%s/%s", path, INIT_DATA_FILE);
            shmem_seg_name = ftok(init_data_path, 1);
            if (shmem_seg_name != -1) {
                destroy_shmem(shmem_seg_name);
            }
#endif
#endif
            if (!gstate.active_tasks.is_slot_dir_in_use(path)) {
                client_clean_out_dir(path, "delete old slot dirs");
                remove_project_owned_dir(path);
            }
        } else {
            delete_project_owned_file(path, false);
        }
    }
    dir_close(dirp);
}
Exemplo n.º 5
0
// recursively delete everything in the specified directory
// (but not the directory itself).
// If an error occurs, delete as much as possible.
//
int client_clean_out_dir(const char* dirpath, const char* reason) {
    char filename[256], path[256];
    int retval, final_retval = 0;
    DIRREF dirp;

    if (reason && log_flags.slot_debug) {
        msg_printf(0, MSG_INFO, "[slot] cleaning out %s: %s", dirpath, reason);
    }
    dirp = dir_open(dirpath);
    if (!dirp) {
#ifndef _WIN32
        if (g_use_sandbox && (errno == EACCES)) {
            // dir may be owned by boinc_apps
            return remove_project_owned_file_or_dir(dirpath);
        }
#endif
        return 0;    // if dir doesn't exist, it's empty
    }

    while (1) {
        strcpy(filename, "");
        retval = dir_scan(filename, dirp, sizeof(filename));
        if (retval) break;
        sprintf(path, "%s/%s", dirpath,  filename);
        if (is_dir(path)) {
            retval = client_clean_out_dir(path, NULL);
            if (retval) final_retval = retval;
            retval = remove_project_owned_dir(path);
            if (retval) final_retval = retval;
        } else {
            retval = delete_project_owned_file(path, false);
            if (retval) final_retval = retval;
        }
    }
    dir_close(dirp);
    return final_retval;
}