Clojure-Contrib

clojure.contrib.io does not support appending anymore

Details

  • Type: Defect Defect
  • Status: In Progress In Progress
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Reproduce the bug with:

(require 'clojure.contrib.io)
(clojure.contrib.io/append-writer "/xyz.txt")
</code></pre>
which will throw an Exception ���Cannot change an open stream to append mode���.

This is caused because of a flaw in the call chain.
*clojure.contrib.io/writer* for Strings calls again *writer* for whatever *clojure.contrib.io/output-stream*
returns. We call *append-writer* which then calls *writer* on the String which in turn then calls:
<pre><code>
output-stream for ^String which calls
    output-stream for ^URL which calls
        output-stream for ^File which binds *append* to false and calls
            output-stream for ^OutputStream which
            returns a BufferedOutputStream instance which then jumps back to the
        ^File handler, which removes its binding for *append*!! and returns the BOS to the
    ^URL handler which returns the BOS to the
^String handler

At this point the outer binding (for append) is set to true again, and assert-not-appending fails.

Activity

Hide
Assembla Importer added a comment -

bpsm said: I've looked at this defect (on master). It seems thorny to me.

I'm finding the control flow in c.c.io rather difficult to follow, what with all those extensions of the Streams protocol delegating to one-another. I'm reasonably certain that the solution is to special case the creation of a reader in append mode.

I'll attach a patch that does this by providing a default implementation for :writer, which seems to solve the problem, but I think I still need to think about it some more before I can call it 'done'.

Note: this defect is also present in clojure.java.io 1.2.0.

Show
Assembla Importer added a comment - bpsm said: I've looked at this defect (on master). It seems thorny to me. I'm finding the control flow in c.c.io rather difficult to follow, what with all those extensions of the Streams protocol delegating to one-another. I'm reasonably certain that the solution is to special case the creation of a reader in append mode. I'll attach a patch that does this by providing a default implementation for :writer, which seems to solve the problem, but I think I still need to think about it some more before I can call it 'done'. Note: this defect is also present in clojure.java.io 1.2.0.
Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - bpsm said: [file:auuXEWSiur35DyeJe5cbCb]
Hide
Assembla Importer added a comment -

bpsm said: Correction: This issue is not present in clojure 1.2.0. my bad.
I was mistaken about this bug being present in clojure.java.io. append-writer doesn't even exist there and the append magic is gone there too as per clojure#311.
I think there was just something wonky with my swank-clojure:

clojure.contrib.io> (require 'clojure.java.io)
nil
clojure.contrib.io> (in-ns 'clojure.java.io)
#<Namespace clojure.java.io>
clojure.java.io> (with-open [x (append-writer "/tmp/foo.txt")] x)
; Evaluation aborted.  ;;; EXCEPTION HERE
Show
Assembla Importer added a comment - bpsm said: Correction: This issue is not present in clojure 1.2.0. my bad. I was mistaken about this bug being present in clojure.java.io. append-writer doesn't even exist there and the append magic is gone there too as per clojure#311. I think there was just something wonky with my swank-clojure:
clojure.contrib.io> (require 'clojure.java.io)
nil
clojure.contrib.io> (in-ns 'clojure.java.io)
#<Namespace clojure.java.io>
clojure.java.io> (with-open [x (append-writer "/tmp/foo.txt")] x)
; Evaluation aborted.  ;;; EXCEPTION HERE
Hide
Assembla Importer added a comment -

bpsm said: [file:amTyVwSt8r378NeJe5cbLr]: regression test

Show
Assembla Importer added a comment - bpsm said: [file:amTyVwSt8r378NeJe5cbLr]: regression test
Hide
Assembla Importer added a comment -

bpsm said: The provided regression test demonstrates the described issue and confirms that the provided patch resolves the issue. All other io unit tests continue to pass.

Show
Assembla Importer added a comment - bpsm said: The provided regression test demonstrates the described issue and confirms that the provided patch resolves the issue. All other io unit tests continue to pass.
Hide
Assembla Importer added a comment -

stuart.sierra said: clojure.contrib.io is deprecated and will be removed before the next release.

Show
Assembla Importer added a comment - stuart.sierra said: clojure.contrib.io is deprecated and will be removed before the next release.
Hide
Assembla Importer added a comment -

bpsm said: Let's see if I'm on the same page that you're on:

Since 1.2.0 is at RC3 already, you must mean 1.3.0 when you say "next release", yes/no? Predicated on that:

  • I think this should be fixed on the 1.2.x branch, where c.c.io is available, though deprecated. ("deprecated, but working" is better than "deprecated by slightly buggy.") The attached patch is against 1.2.x, not master, despite what my initial comment on this issue says.
  • I've provided a patch on #93 to remove c.c.io on master (1.3.x).
Show
Assembla Importer added a comment - bpsm said: Let's see if I'm on the same page that you're on: Since 1.2.0 is at RC3 already, you must mean 1.3.0 when you say "next release", yes/no? Predicated on that:
  • I think this should be fixed on the 1.2.x branch, where c.c.io is available, though deprecated. ("deprecated, but working" is better than "deprecated by slightly buggy.") The attached patch is against 1.2.x, not master, despite what my initial comment on this issue says.
  • I've provided a patch on #93 to remove c.c.io on master (1.3.x).

People

  • Assignee:
    bpsm
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated: