コード例 #1
0
ファイル: commonfs.c プロジェクト: gtrs/hubicfuse
//check if local path is in cache, without downloading from cloud if not in cache
dir_entry* check_path_info(const char* path)
{
  debugf(DBG_LEVEL_EXT, "check_path_info(%s)", path);
  char dir[MAX_PATH_SIZE];
  dir_for(path, dir);
  dir_entry* tmp;

  //get parent folder cache entry
  if (!check_caching_list_directory(dir, &tmp))
  {
    debugf(DBG_LEVEL_EXT, "exit 0: check_path_info(%s) "KYEL"[CACHE-MISS]", path);
    return NULL;
  }
  for (; tmp; tmp = tmp->next)
  {
    if (!strcmp(tmp->full_name, path))
    {
      debugf(DBG_LEVEL_EXT, "exit 1: check_path_info(%s) "KGRN"[CACHE-HIT]", path);
      return tmp;
    }
  }
  if (!strcmp(path, "/"))
    debugf(DBG_LEVEL_EXT,
           "exit 2: check_path_info(%s) "KYEL"ignoring root [CACHE-MISS]", path);
  else
    debugf(DBG_LEVEL_EXT, "exit 3: check_path_info(%s) "KYEL"[CACHE-MISS]", path);
  return NULL;
}
コード例 #2
0
ファイル: commonfs.c プロジェクト: gtrs/hubicfuse
dir_entry* path_info(const char* path)
{
  debugf(DBG_LEVEL_EXT, "path_info(%s)", path);
  char dir[MAX_PATH_SIZE];
  dir_for(path, dir);
  dir_entry* tmp;
  if (!caching_list_directory(dir, &tmp))
  {
    debugf(DBG_LEVEL_EXT, "exit 0: path_info(%s) "KYEL"[CACHE-DIR-MISS]", dir);
    return NULL;
  }
  else
    debugf(DBG_LEVEL_EXT, "path_info(%s) "KGRN"[CACHE-DIR-HIT]", dir);
  //iterate in file list obtained from cache or downloaded
  for (; tmp; tmp = tmp->next)
  {
    if (!strcmp(tmp->full_name, path))
    {
      debugf(DBG_LEVEL_EXT, "exit 1: path_info(%s) "KGRN"[CACHE-FILE-HIT]", path);
      return tmp;
    }
  }
  //miss in case the file is not found on a cached folder
  debugf(DBG_LEVEL_EXT, "exit 2: path_info(%s) "KYEL"[CACHE-MISS]", path);
  return NULL;
}
コード例 #3
0
ファイル: commonfs.c プロジェクト: gtrs/hubicfuse
dir_entry* check_parent_folder_for_file(const char* path)
{
  char dir[MAX_PATH_SIZE];
  dir_for(path, dir);
  dir_entry* tmp;
  if (!check_caching_list_directory(dir, &tmp))
    return NULL;
  else
    return tmp;
}
コード例 #4
0
ファイル: commonfs.c プロジェクト: gtrs/hubicfuse
void dir_decache(const char* path)
{
  dir_cache* cw;
  debugf(DBG_LEVEL_NORM, "dir_decache(%s)", path);
  pthread_mutex_lock(&dcachemut);
  dir_entry* de, *tmpde;
  char dir[MAX_PATH_SIZE];
  dir_for(path, dir);
  for (cw = dcache; cw; cw = cw->next)
  {
    debugf(DBG_LEVEL_EXT, "dir_decache: parse(%s)", cw->path);
    if (!strcmp(cw->path, path))
    {
      if (cw == dcache)
        dcache = cw->next;
      if (cw->prev)
        cw->prev->next = cw->next;
      if (cw->next)
        cw->next->prev = cw->prev;
      debugf(DBG_LEVEL_EXT, "dir_decache: free_dir1(%s)", cw->path);
      //fixme: this sometimes is NULL and generates segfaults, checking first
      if (cw->entries != NULL)
        cloudfs_free_dir_list(cw->entries);
      free(cw->path);
      free(cw);
    }
    else if (cw->entries && !strcmp(dir, cw->path))
    {
      if (!strcmp(cw->entries->full_name, path))
      {
        de = cw->entries;
        cw->entries = de->next;
        de->next = NULL;
        debugf(DBG_LEVEL_EXT, "dir_decache: free_dir2()");
        cloudfs_free_dir_list(de);
      }
      else for (de = cw->entries; de->next; de = de->next)
        {
          if (!strcmp(de->next->full_name, path))
          {
            tmpde = de->next;
            de->next = de->next->next;
            tmpde->next = NULL;
            debugf(DBG_LEVEL_EXT, "dir_decache: free_dir3()", cw->path);
            cloudfs_free_dir_list(tmpde);
            break;
          }
        }
    }
  }
  pthread_mutex_unlock(&dcachemut);
}
コード例 #5
0
ファイル: cloudfuse.c プロジェクト: gokuale/hubicfuse
static void update_dir_cache(const char *path, off_t size, int isdir, int islink)
{
    pthread_mutex_lock(&dmut);
    dir_cache *cw;
    dir_entry *de;
    char dir[MAX_PATH_SIZE];
    dir_for(path, dir);
    for (cw = dcache; cw; cw = cw->next)
    {
        if (!strcmp(cw->path, dir))
        {
            for (de = cw->entries; de; de = de->next)
            {
                if (!strcmp(de->full_name, path))
                {
                    de->size = size;
                    pthread_mutex_unlock(&dmut);
                    return;
                }
            }
            de = (dir_entry *)malloc(sizeof(dir_entry));
            de->size = size;
            de->isdir = isdir;
            de->islink = islink;
            de->name = strdup(&path[strlen(cw->path)+1]);
            de->full_name = strdup(path);

            if (isdir)
            {
                de->content_type = strdup("application/link");
            }
            if(islink)
            {
                de->content_type = strdup("application/directory");
            }
            else
            {

                de->content_type = strdup("application/octet-stream");
            }
            de->last_modified = time(NULL);
            de->next = cw->entries;
            cw->entries = de;
            if (isdir)
                new_cache(path);
            break;
        }
    }
    pthread_mutex_unlock(&dmut);
}
コード例 #6
0
ファイル: cloudfuse.c プロジェクト: gokuale/hubicfuse
static dir_entry *path_info(const char *path)
{
    char dir[MAX_PATH_SIZE];
    dir_for(path, dir);
    dir_entry *tmp;
    if (!caching_list_directory(dir, &tmp))
        return NULL;
    for (; tmp; tmp = tmp->next)
    {
        if (!strcmp(tmp->full_name, path))
            return tmp;
    }
    return NULL;
}
コード例 #7
0
ファイル: commonfs.c プロジェクト: gtrs/hubicfuse
//check for file in cache, if found size will be updated, if not found
//and this is a dir, a new dir cache entry is created
void update_dir_cache(const char* path, off_t size, int isdir, int islink)
{
  debugf(DBG_LEVEL_EXTALL, KCYN "update_dir_cache(%s)", path);
  pthread_mutex_lock(&dcachemut);
  dir_cache* cw;
  dir_entry* de;
  char dir[MAX_PATH_SIZE];
  dir_for(path, dir);
  for (cw = dcache; cw; cw = cw->next)
  {
    if (!strcmp(cw->path, dir))
    {
      for (de = cw->entries; de; de = de->next)
      {
        if (!strcmp(de->full_name, path))
        {
          de->size = size;
          pthread_mutex_unlock(&dcachemut);
          debugf(DBG_LEVEL_EXTALL, "exit 0: update_dir_cache(%s)", path);
          return;
        }
      }
      de = init_dir_entry();
      de->size = size;
      de->isdir = isdir;
      de->islink = islink;
      de->name = strdup(&path[strlen(cw->path) + 1]);
      de->full_name = strdup(path);
      //fixed: the conditions below were mixed up dir -> link?
      if (islink)
        de->content_type = strdup("application/link");
      if (isdir)
        de->content_type = strdup("application/directory");
      else
        de->content_type = strdup("application/octet-stream");
      de->next = cw->entries;
      cw->entries = de;
      if (isdir)
        new_cache(path);
      break;
    }
  }
  debugf(DBG_LEVEL_EXTALL, "exit 1: update_dir_cache(%s)", path);
  pthread_mutex_unlock(&dcachemut);
}
コード例 #8
0
ファイル: cloudfuse.c プロジェクト: gokuale/hubicfuse
static void dir_decache(const char *path)
{
    dir_cache *cw;
    pthread_mutex_lock(&dmut);
    dir_entry *de, *tmpde;
    char dir[MAX_PATH_SIZE];
    dir_for(path, dir);
    for (cw = dcache; cw; cw = cw->next)
    {
        if (!strcmp(cw->path, path))
        {
            if (cw == dcache)
                dcache = cw->next;
            if (cw->prev)
                cw->prev->next = cw->next;
            if (cw->next)
                cw->next->prev = cw->prev;
            cloudfs_free_dir_list(cw->entries);
            free(cw->path);
            free(cw);
        }
        else if (cw->entries && !strcmp(dir, cw->path))
        {
            if (!strcmp(cw->entries->full_name, path))
            {
                de = cw->entries;
                cw->entries = de->next;
                de->next = NULL;
                cloudfs_free_dir_list(de);
            }
            else for (de = cw->entries; de->next; de = de->next)
                {
                    if (!strcmp(de->next->full_name, path))
                    {
                        tmpde = de->next;
                        de->next = de->next->next;
                        tmpde->next = NULL;
                        cloudfs_free_dir_list(tmpde);
                        break;
                    }
                }
        }
    }
    pthread_mutex_unlock(&dmut);
}