Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rename support

  • Loading branch information...
commit b45128289f3a30bd1a4b741c5f2eef95790bfad0 1 parent 1dd8872
@mikejs authored
Showing with 42 additions and 0 deletions.
  1. +1 −0  main.cpp
  2. +39 −0 operations.cpp
  3. +2 −0  operations.h
View
1  main.cpp
@@ -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
39 operations.cpp
@@ -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
2  operations.h
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.