Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Created March 22, 2010 05:26
Show Gist options
  • Save billywhizz/339815 to your computer and use it in GitHub Desktop.
Save billywhizz/339815 to your computer and use it in GitHub Desktop.
diff --git a/lib/fs.js b/lib/fs.js
old mode 100644
new mode 100755
index f9fc339..797f104
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -162,6 +162,22 @@ exports.truncateSync = function (fd, len) {
return fs.truncate(fd, len);
};
+exports.fdatasync = function (fd, callback) {
+ fs.fdatasync(fd, callback || noop);
+};
+
+exports.fdatasyncSync = function (fd) {
+ return fs.fdatasync(fd);
+};
+
+exports.fsync = function (fd, callback) {
+ fs.fsync(fd, callback || noop);
+};
+
+exports.fsyncSync = function (fd) {
+ return fs.fsync(fd);
+};
+
exports.rmdir = function (path, callback) {
fs.rmdir(path, callback || noop);
};
diff --git a/src/node_constants.cc b/src/node_constants.cc
old mode 100644
new mode 100755
index a28bad4..9045291
--- a/src/node_constants.cc
+++ b/src/node_constants.cc
@@ -51,6 +51,10 @@ void DefineConstants(Handle<Object> target) {
NODE_DEFINE_CONSTANT(target, O_APPEND);
#endif
+#ifdef O_DIRECT
+ NODE_DEFINE_CONSTANT(target, O_DIRECT);
+#endif
+
#ifdef O_DIRECTORY
NODE_DEFINE_CONSTANT(target, O_DIRECTORY);
#endif
diff --git a/src/node_file.cc b/src/node_file.cc
old mode 100644
new mode 100755
index 5ca5416..4fb572b
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -309,6 +309,42 @@ static Handle<Value> Truncate(const Arguments& args) {
}
}
+static Handle<Value> Fdatasync(const Arguments& args) {
+ HandleScope scope;
+
+ if (args.Length() < 2 || !args[0]->IsInt32()) {
+ return THROW_BAD_ARGS;
+ }
+
+ int fd = args[0]->Int32Value();
+
+ if (args[1]->IsFunction()) {
+ ASYNC_CALL(fdatasync, args[1], fd)
+ } else {
+ int ret = fdatasync(fd);
+ if (ret != 0) return ThrowException(errno_exception(errno));
+ return Undefined();
+ }
+}
+
+static Handle<Value> Fsync(const Arguments& args) {
+ HandleScope scope;
+
+ if (args.Length() < 2 || !args[0]->IsInt32()) {
+ return THROW_BAD_ARGS;
+ }
+
+ int fd = args[0]->Int32Value();
+
+ if (args[1]->IsFunction()) {
+ ASYNC_CALL(fsync, args[1], fd)
+ } else {
+ int ret = fsync(fd);
+ if (ret != 0) return ThrowException(errno_exception(errno));
+ return Undefined();
+ }
+}
+
static Handle<Value> Unlink(const Arguments& args) {
HandleScope scope;
@@ -636,6 +672,8 @@ void File::Initialize(Handle<Object> target) {
NODE_SET_METHOD(target, "close", Close);
NODE_SET_METHOD(target, "open", Open);
NODE_SET_METHOD(target, "read", Read);
+ NODE_SET_METHOD(target, "fdatasync", Fdatasync);
+ NODE_SET_METHOD(target, "fsync", Fsync);
NODE_SET_METHOD(target, "rename", Rename);
NODE_SET_METHOD(target, "truncate", Truncate);
NODE_SET_METHOD(target, "rmdir", RMDir);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment