int update(char* dest, char* file, int client_id){ string container; fstree_t client_tree; client_tree = repository_tree; fstree_node_t current = client_tree->root; char * child_file, * position, *command, *server_folder, *client_folder; if (!strcmp(file,".")){ container = remove_last_appended(dest); run_command(COMMAND_RM, dest, NULL); return checkout(container, client_id); } child_file = (char *)calloc(MAX_PATH_LENGTH, sizeof(char)); server_folder = (char *)calloc(MAX_PATH_LENGTH, sizeof(char)); client_folder = (char *)calloc(MAX_PATH_LENGTH, sizeof(char)); command = (char *)calloc(MAX_PATH_LENGTH, sizeof(char)); strcpy(child_file, file); strcpy(server_folder, REPOSITORY_PATH); strcpy(client_folder, dest); while (position = strchr(child_file, '/')) { *position = 0; current = find_child_by_path(current,child_file); if (current == NULL) return -1; if (check_existing_file(client_folder, child_file) == NON_EXISTING_FILE) { strcpy(command,"mkdir "); strcat(command,client_folder); strcat(command,"/"); strcat(command,child_file); system(command); } strcat(client_folder,"/"); strcat(client_folder,child_file); strcat(server_folder,"/"); strcat(server_folder,child_file); child_file = position+1; } current = find_child_by_path(current,child_file); if (current != NULL){ strcpy(command,"cp -rf "); strcat(command,server_folder); strcat(command,"/"); strcat(command,child_file); strcat(command," "); strcat(command,client_folder); system(command); } else { client_send("File not found in server", client_id); client_send(END_OF_TRANSMISSION, client_id); return -1; } client_send("Updated", client_id); client_send(END_OF_TRANSMISSION, client_id); return SUCCESS; }
GF_EXPORT GF_Err gf_node_store_embedded_data(XMLRI *iri, const char *cache_dir, const char *base_filename) { char szFile[GF_MAX_PATH], buf[20], *sep, *data, *ext; u32 data_size, idx; Bool existing; FILE *f; if (!cache_dir || !base_filename || !iri || !iri->string || strncmp(iri->string, "data:", 5)) return GF_OK; /*handle "data:" scheme when cache is specified*/ strcpy(szFile, cache_dir); data_size = (u32) strlen(szFile); if (szFile[data_size-1] != GF_PATH_SEPARATOR) { szFile[data_size] = GF_PATH_SEPARATOR; szFile[data_size+1] = 0; } if (base_filename) { sep = strrchr(base_filename, GF_PATH_SEPARATOR); #ifdef WIN32 if (!sep) sep = strrchr(base_filename, '/'); #endif if (!sep) sep = (char *) base_filename; else sep += 1; strcat(szFile, sep); } sep = strrchr(szFile, '.'); if (sep) sep[0] = 0; strcat(szFile, "_img_"); /*get mime type*/ sep = (char *)iri->string + 5; if (!strncmp(sep, "image/jpg", 9) || !strncmp(sep, "image/jpeg", 10)) ext = ".jpg"; else if (!strncmp(sep, "image/png", 9)) ext = ".png"; else if (!strncmp(sep, "image/svg+xml", 13)) ext = ".svg"; else return GF_BAD_PARAM; data = NULL; sep = strchr(iri->string, ';'); if (!strncmp(sep, ";base64,", 8)) { sep += 8; data_size = 2 * (u32) strlen(sep); data = (char*)gf_malloc(sizeof(char)*data_size); if (!data) return GF_OUT_OF_MEM; data_size = gf_base64_decode(sep, (u32) strlen(sep), data, data_size); } else if (!strncmp(sep, ";base16,", 8)) { data_size = 2 * (u32) strlen(sep); data = (char*)gf_malloc(sizeof(char)*data_size); if (!data) return GF_OUT_OF_MEM; sep += 8; data_size = gf_base16_decode(sep, (u32) strlen(sep), data, data_size); } if (!data_size) return GF_OK; iri->type = XMLRI_STRING; existing = 0; idx = 0; while (1) { u32 res = check_existing_file(szFile, ext, data, data_size, idx); if (!res) break; if (res==2) { existing = 1; break; } idx++; } sprintf(buf, "%04X", idx); strcat(szFile, buf); strcat(szFile, ext); if (!existing) { f = gf_f64_open(szFile, "wb"); if (!f) { gf_free(data); gf_free(iri->string); iri->string = NULL; return GF_IO_ERR; } gf_fwrite(data, data_size, 1, f); fclose(f); } gf_free(data); gf_free(iri->string); iri->string = gf_strdup(szFile); return GF_OK; }