Package: nodejs / 0.10.29~dfsg-2

1001_readfile_eisdir.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Description: raise EISDIR if readFile or readFileSync a directory
Bug-Node: https://github.com/joyent/node/pull/5928
Author: Jérémy Lal <kapouer@melix.org>
Last-Update: 2013-07-28
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -213,7 +213,8 @@
           callback(er);
         });
       }
-
+      // some platforms do not throw EISDIR.
+      if (st.isDirectory()) return callback(errnoException('EISDIR', 'read'));
       size = st.size;
       if (size === 0) {
         // the kernel lies about many files.
@@ -291,7 +292,10 @@
   var size;
   var threw = true;
   try {
-    size = fs.fstatSync(fd).size;
+    var st = fs.fstatSync(fd);
+    // some platforms do not throw EISDIR.
+    if (st.isDirectory && st.isDirectory()) throw errnoException('EISDIR', 'read');
+    size = st.size;
     threw = false;
   } finally {
     if (threw) fs.closeSync(fd);