示例#1
0
文件: tagfs.c 项目: SimoRihani/it-202
int tagfs_link(const char *file, const char *tags){
  LOGCALL();

  char **tagsbuf;
  comm_getTags(tags, &tagsbuf);
  char **tmp = tagsbuf;
  int cpt = 0, i;

  while(tmp != NULL && strcmp(file + 1, *tmp) != 0){
    tmp++;
    cpt++;
  }

  if(*tmp == NULL || *(tmp + 1) != NULL){
    comm_freeTags(tagsbuf);
    return FAILURE;
  }

  if (!exist_file(db, file + 1))
	add_new_file(db, file + 1);
  for(i = 0; i < cpt; ++i)
    add_tag_to_file(db, file + 1, tagsbuf[i]);

  comm_freeTags(tagsbuf);
  return SUCCESS;
}
示例#2
0
int tagfs_rename(const char *path, const char *newpath) {
	char **tag_array = NULL;
	int file_id = 0;
	int i = 0;
	int num_tags = 0;
	int retstat = 0;

	DEBUG(ENTRY);
	INFO("Moving %s to %s", path, newpath);

	file_id = file_id_from_path(path);
	remove_tags(file_id);

	if(strcmp(dirname(newpath), "/") != 0) { /* deleting will put the file at root. Nothing to add */
		num_tags = path_to_array(dirname(newpath), &tag_array);

		for(i = 0; i < num_tags; i++) {
			add_tag_to_file(tag_id_from_tag_name(tag_array[i]), file_id);
		}

		free_double_ptr((void ***)&tag_array, num_tags);
	}

	DEBUG(EXIT);
	return retstat;
}