Example #1
0
int gridfs_flush(const char* path, struct fuse_file_info *ffi)
{
  path = fuse_to_mongo_path(path);

  if(!ffi->fh) {
    return 0;
  }

  map<string,LocalGridFile*>::iterator file_iter;
  file_iter = open_files.find(path);
  if(file_iter == open_files.end()) {
    return -ENOENT;
  }

  LocalGridFile *lgf = file_iter->second;

  if(!lgf->dirty()) {
    return 0;
  }

  ScopedDbConnection sdc(*gridfs_options.conn_string);
  bool digest = true;
  string err = "";
  sdc.conn().DBClientWithCommands::auth(gridfs_options.db, gridfs_options.username, gridfs_options.password, err, digest);
  fprintf(stderr, "DEBUG: %s\n", err.c_str());
  GridFS gf(sdc.conn(), gridfs_options.db);

  if(gf.findFile(path).exists()) {
    gf.removeFile(path);
  }

  size_t len = lgf->getLength();
  char *buf = new char[len];
  lgf->read(buf, len, 0);

  gf.storeFile(buf, len, path);

  sdc.done();

  lgf->flushed();

  return 0;
}
Example #2
0
int gridfs_flush(const char* path, struct fuse_file_info *ffi)
{
  path = fuse_to_mongo_path(path);

  if(!ffi->fh) {
    return 0;
  }

  map<string,LocalGridFile*>::iterator file_iter;
  file_iter = open_files.find(path);
  if(file_iter == open_files.end()) {
    return -ENOENT;
  }

  LocalGridFile *lgf = file_iter->second;

  if(!lgf->dirty()) {
    return 0;
  }

  ScopedDbConnection sdc(*gridfs_options.conn_string);
  ScopedDbConnection_init(sdc);
  GridFS gf(sdc.conn(), gridfs_options.db, gridfs_options.prefix);

  if(gf.findFile(path).exists()) {
    gf.removeFile(path);
  }

  size_t len = lgf->getLength();
  char *buf = new char[len];
  lgf->read(buf, len, 0);

  gf.storeFile(buf, len, path);

  sdc.done();

  lgf->flushed();

  return 0;
}