Consider gzip/gunzip to self

Open
#225 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
clojure
Domain
tooling

Research direction

Start at the public gzip and gunzip entry points and reproduce the self-targeting examples from the issue. Compare their behavior with copy and move, then inspect any existing tests around file transformation and overwrite handling. Done means the project has an agreed, documented or enforced behavior for gzip/gunzip targeting the source itself.

Written by the indexing model from the issue text.

Description

Scenario

I have noticed that it is technically possible to request a gzip to self:

(require '[babashka.fs :as fs])

(spit "foo.txt" "foo")
(fs/gzip "foo.txt" {:out-file "foo.txt"})
;; => "./foo.txt"

And then to gunzip to self:

(fs/gunzip "foo.txt")
;; => Execution error (FileAlreadyExistsException) at sun.nio.fs.UnixException/translateToIOException (UnixException.java:94).
;;    ./foo.txt
(fs/gunzip "foo.txt" "." {:replace-existing true})
;; => 10

But if we then slurp the resulting foo.txt

(slurp "foo.txt")
;; => "�\b\0\0\0\0\0\0�"

We see that it is not the gunzipped file.

Option 0 - Do nothing

Users should know not to do that.

Option 1 - Doc

Add a little note to docstrings that gzip/gunzip to self is not supported

Option 2 - Throw

Throw when attempting to zip/unzip to self

Option 3 - Support Use Case

Actually allow for gzip/gunzip to self.

What do other fns do?

I looked at copy and move.
They are no-ops when copying/moving to self.
But they are different from gzip gunzip which also does a transformation.
So, not applicable.

copy-tree does throw on an attempt to copy under itself.

Proposal

I think Option 3 - support use case - is too obscure to bother with.

My preference is Option 2 - throw.
Explicitly don't allow it.
Help users discover they made a mistake.

But I think Option 1 - doc - is also worth considering.

Whatcha think?

Dominant language
Clojure
Stars
221
Forks
52
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from babashka/fs

All issues in babashka/fs

Similar issues

More Clojure issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.