From 9f65f27ac92c8ce7fa6ea7f03d6f59c54d6f1b22 Mon Sep 17 00:00:00 2001
From: Hisham Muhammad <hisham@gobolinux.org>
Date: Fri, 10 Sep 2010 14:32:08 -0300
Subject: Improve behavior of --local check.

---
 src/luarocks/build.lua   | 2 +-
 src/luarocks/install.lua | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index b7386688..6eca0c3e 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -278,7 +278,7 @@ function run(...)
    end
    assert(type(version) == "string" or not version)
 
-   if not flags["local"] and not fs.is_writable(cfg.root_dir) then
+   if not flags["local"] and (fs.exists(cfg.root_dir) and not fs.is_writable(cfg.root_dir)) then
       return nil, "Your user does not have write permissions in " .. cfg.root_dir ..
                   " \n-- you may want to run as a privileged user or use your local tree with --local."
    end
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index 4bb073dc..f9f27ccf 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -107,14 +107,14 @@ function run(...)
       return nil, "Argument missing, see help."
    end
 
-   if not flags["local"] and not fs.is_writable(cfg.root_dir) then
+   if not flags["local"] and (fs.exists(cfg.root_dir) and not fs.is_writable(cfg.root_dir)) then
       return nil, "Your user does not have write permissions in " .. cfg.root_dir ..
                   " \n-- you may want to run as a privileged user or use your local tree with --local."
    end
 
    if name:match("%.rockspec$") or name:match("%.src%.rock$") then
       local build = require("luarocks.build")
-      return build.run(name)
+      return build.run(name, flags["local"] and "--local")
    elseif name:match("%.rock$") then
       return install_binary_rock(name)
    else
-- 
cgit v1.2.3-55-g6feb