Exemplo n.º 1
0
  void
  FilesystemEntry::remove()
  {
    gridfs().removeFile(path());

    synchonizeUpdate();
  }
Exemplo n.º 2
0
extern "C" gridfile_t get_gridfile(const char* mongod_host, const char* gridfs_db, const char* gridfs_root_collection, const char* filename) {
    gridfile_t mongo_exception = {
        1,
        0,
        "",
        ""
    };
    gridfile_t no_file = {
        2,
        0,
        "",
        ""
    };
		
	std::string host = std::string(mongod_host);
	mongo::ScopedDbConnection conn(host);

    mongo::GridFS gridfs(conn.conn(), std::string(gridfs_db), std::string(gridfs_root_collection));
    mongo::GridFile gridfile = gridfs.findFile(std::string(filename));

    if (!gridfile.exists()) {
        return no_file;
    }

	std::stringstream oss (std::stringstream::in | std::stringstream::out | std::stringstream::binary);
	gridfile.write(oss);

    char* buffer;
    long size;
    size = gridfile.getContentLength();
    buffer = new char[size];
    oss.read(buffer, size);

    gridfile_t result = {
        0,
        size,
        buffer,
        gridfile.getContentType().c_str() /*"text/plain"*/ /* TODO use real mimetype */
    };

	conn.done();
    return result;
}
Exemplo n.º 3
0
  void
  FilesystemEntry::create(
      mode_t mode,
      uid_t uid,
      gid_t gid,
      const std::string& content)
  {
    // we use the content type to store some extra meta data
    std::stringstream lContentType;    
    lContentType << "m:" << mode << "|u:" << uid << "|g:" << gid << "|t:" << time(0);
    const char* data = content.c_str();
    size_t length = content.length();

    gridfs().storeFile(data, length, path(), lContentType.str());    

    synchonizeUpdate();

    //force reload
    force_reload();
  }