Permalink
Browse files

rename support

  • Loading branch information...
1 parent 1dd8872 commit b45128289f3a30bd1a4b741c5f2eef95790bfad0 @mikejs committed Sep 28, 2009
Showing with 42 additions and 0 deletions.
  1. +1 −0 main.cpp
  2. +39 −0 operations.cpp
  3. +2 −0 operations.h
View
@@ -37,6 +37,7 @@ int main(int argc, char *argv[])
gridfs_oper.setxattr = gridfs_setxattr;
gridfs_oper.write = gridfs_write;
gridfs_oper.flush = gridfs_flush;
+ gridfs_oper.rename = gridfs_rename;
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
View
@@ -395,3 +395,42 @@ int gridfs_flush(const char* path, struct fuse_file_info *ffi)
return 0;
}
+
+int gridfs_rename(const char* old_path, const char* new_path)
+{
+ old_path = fuse_to_mongo_path(old_path);
+ new_path = fuse_to_mongo_path(new_path);
+
+ ScopedDbConnection sdc(gridfs_options.host);
+ DBClientBase &client = sdc.conn();
+
+ string db_name = gridfs_options.db;
+
+ BSONObj file_obj = client.findOne(db_name + ".fs.files",
+ BSON("filename" << old_path));
+
+ if(file_obj.isEmpty()) {
+ return -ENOENT;
+ }
+
+ BSONObjBuilder b;
+ set<string> field_names;
+ file_obj.getFieldNames(field_names);
+
+ for(set<string>::iterator name = field_names.begin();
+ name != field_names.end(); name++)
+ {
+ if(*name != "filename") {
+ b.append(file_obj.getField(*name));
+ }
+ }
+
+ b << "filename" << new_path;
+
+ client.update(db_name + ".fs.files",
+ BSON("_id" << file_obj.getField("_id")), b.obj());
+
+ sdc.done();
+
+ return 0;
+}
View
@@ -50,4 +50,6 @@ int gridfs_write(const char* path, const char* buf, size_t nbyte,
int gridfs_flush(const char* path, struct fuse_file_info* ffi);
+int gridfs_rename(const char* old_path, const char* new_path);
+
#endif

0 comments on commit b451282

Please sign in to comment.