Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Check writable-ness more precisely

  • Loading branch information...
commit b23b2638b68211d9a542568debfdfb598dc53386 1 parent 4b4df2f
Isaac Z. Schlueter authored January 29, 2012

Showing 1 changed file with 26 additions and 1 deletion. Show diff stats Hide diff stats

  1. 27  rimraf.js
27  rimraf.js
@@ -71,11 +71,36 @@ function rimraf_ (p, opts, cb) {
71 71
   })
72 72
 }
73 73
 
  74
+
  75
+var myGid = function myGid () {
  76
+  var g = process.getuid && process.getgid()
  77
+  myGid = function myGid () { return g }
  78
+  return g
  79
+}
  80
+
  81
+var myUid = function myUid () {
  82
+  var u = process.getuid && process.getuid()
  83
+  myUid = function myUid () { return u }
  84
+  return u
  85
+}
  86
+
  87
+
  88
+function writable (s) {
  89
+  var mode = s.mode && 0777
  90
+    , uid = myUid()
  91
+    , gid = myGid()
  92
+  return (mode & 0002)
  93
+      || (gid === s.gid && (mode & 0020))
  94
+      || (uid === s.uid && (mode & 0200))
  95
+}
  96
+
74 97
 function rm_ (p, s, opts, cb) {
75 98
   if (!s.isDirectory()) {
76 99
     // check if the file is writable
77  
-    if ((s.mode & 0222) !== 0222) {
  100
+    if (!writable(s)) {
78 101
       // make file writable
  102
+      // user/group/world, doesn't matter at this point
  103
+      // since it's about to get nuked.
79 104
       return fs.chmod(p, s.mode | 0222, function (er) {
80 105
         if (er) return cb(er)
81 106
         fs.unlink(p, cb)

0 notes on commit b23b263

Please sign in to comment.
Something went wrong with that request. Please try again.