Tempfile#path should return nil after #delete
---------------------------------------------

                 Key: JRUBY-5144
                 URL: http://jira.codehaus.org/browse/JRUBY-5144
             Project: JRuby
          Issue Type: Bug
          Components: Standard Library
    Affects Versions: JRuby 1.5.3
            Reporter: Aman Gupta
            Assignee: Thomas E Enebo
            Priority: Trivial


MRI:
{noformat}
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.3.0]
$ ruby -rtempfile -e' t = Tempfile.new("test"); t.delete; p t.path '
nil
{noformat}

JRuby:
{noformat}
$ jruby -v
jruby 1.5.3 (ruby 1.8.7 patchlevel 249) (2010-09-28 7ca06d7) (Java HotSpot(TM) 
64-Bit Server VM 1.6.0_20) [x86_64-java]
$ jruby -rtempfile -e' t = Tempfile.new("test"); t.delete; p t.path '
"/var/folders/tw/twxUkFedFOeBbjtfFJ-e-++++TM/-Tmp-/test.46959.51441"
{noformat}

Patch:
{noformat}
diff --git a/src/org/jruby/RubyFile.java b/src/org/jruby/RubyFile.java
index a875fdf..325ef49 100644
--- a/src/org/jruby/RubyFile.java
+++ b/src/org/jruby/RubyFile.java
@@ -751,8 +751,8 @@ public class RubyFile extends RubyIO implements 
EncodingCapable {
     }
 
     @JRubyMethod(name = {"path", "to_path"})
-    public RubyString path(ThreadContext context) {
-        return context.getRuntime().newString(path);
+    public IRubyObject path(ThreadContext context) {
+        return path == null ? context.getRuntime().getNil() : 
context.getRuntime().newString(path);
     }
 
     @JRubyMethod
diff --git a/src/org/jruby/RubyTempfile.java b/src/org/jruby/RubyTempfile.java
index 54fe27a..3991ea9 100644
--- a/src/org/jruby/RubyTempfile.java
+++ b/src/org/jruby/RubyTempfile.java
@@ -239,6 +239,7 @@ public class RubyTempfile extends RubyFile {
         if (!tmpFile.exists() || tmpFile.delete()) {
             referenceSet.remove(reaper);
             reaper.released = true;
+            path = null;
         }
         return context.getRuntime().getNil();
     }
{noformat}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to