Code Monkey home page Code Monkey logo

fs's Introduction

fs - File system utilities for Clojure

Build Status

API docs

This library defines some utilities for working with the file system in Clojure. Mostly, it wants to fill the gap that clojure.java.io leaves and add on (and prettify) what java.io.File provides.

Usage

This library is simple. It is just a collection of functions that do things with the file system. The one thing you should understand is *cwd*. This library wraps a lot of built-in Java file systemy things because it pays attention to the *cwd* as the current working directory. Java has no way to change the cwd of a JVM so if you want that behavior, you have to simulate it. This library tries to do that.

The foundation of the library is the file function. It is just like clojure.java.io/file, but it pays attention to the value of *cwd*.

This is 100% a utility library. If you have something useful that it doesn't already have, open a pull request, because I probably want it. Make sure you include tests. Also, make sure they pass.

fs is not an I/O utility library. We should try to keep things limited to file system activities.

Artifacts

Library artifacts are released to Clojars. If you are using Maven, add the following repository definition to your pom.xml:

<repository>
  <id>clojars.org</id>
  <url>http://clojars.org/repo</url>
</repository>

The Most Recent Release

With Leiningen:

[me.raynes/fs "1.4.6"]

With Maven:

<dependency>
  <groupId>me.raynes</groupId>
  <artifactId>fs</artifactId>
  <version>1.4.6</version>
</dependency>

License

Copyright (C) 2010-2013 Miki Tebeka, Anthony Grimes

Distributed under the Eclipse Public License, the same as Clojure.

fs's People

Contributors

alexbaranosky avatar algernon avatar amalloy avatar aphyr avatar bronsa avatar cdombroski avatar chimpymike avatar deduktion avatar egli avatar frozenlock avatar hgiddens avatar jokimaki avatar ktsuji avatar kzar avatar marcomorain avatar miner avatar noprompt avatar raynes avatar rmunn avatar tchagnon avatar tebeka avatar tobereplaced avatar trevor avatar wwentland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fs's Issues

Globbing: support for recursive directory matching `(**)`

Use of ** does not seem to work.

Example directory structure:

/a/b/c/foo.json
/a/b/c/bar.json
/a/b/xyz.json

My expectation is for the use of (fs/glob "**/*.json") to return a list containing three files, representing foo.json, bar.json, and xyz.json.

Instead, I get nil.

Doing (fs/glob (absolute "/a") "**/*.json") results in the same.

For expected behavior, see, e.g., glob behavior on Ruby.

New Maintainer Needed

@Raynes passed away in December of 2016. Like many on GitHub, I didn't know him personally but his contributions to the Clojure community seemed to be endless and our world is poorer for his absence. His passing also leaves an immediate and practical gap due to his generous maintainership of many widely-used libraries. These libraries are in need to new maintainers.

  1. I'm not aware of a centralized effort to coordinate assignment of new maintainers for his projects. If you become aware of such an effort, please link it here.
  2. I don't believe this project has any "collaborators" currently (I might be mistaken), but @Raynes does have collaborators on other projects that might be able to work with Github on an account transfer.
  3. Repository Transfer: I'm not yet able to find any information from Github about whether there is a process for transferring a repository without the owner's consent (I could understand if there is no way, but it would be better for the community to retain url-continuity). Here's the general page on repo-transfers, but it doesn't mention absent-owners: https://help.github.com/articles/about-repository-transfers/ Comments below have information about family/collaborator account transfers.
  4. Clojars Transfer: I'm not super familiar with the clojars deployment process or if there's a process for transferring the package. Are the jars signed? If so it's likely that the key is lost forever.

file function broken on windows

On windows, a path of the form "/a/b/c" (or "\a\b\c") is not considered absolute (since it lacks a drive letter), so the file function will prepend the cwd, returning a bogus path.

Looking at the javadoc for java.io.File, it appears the the getCanonicalPath/getCanonicalFile methods will handle all of the OS complications for us -- they seem to handle both "." and ".." as well as relative paths (without a leading slash). Perhaps the file function could be changed to use getCanonicalFile?

iterate-dir throws OOME on large directory structures

The iterate-dir function consumes all available heap and throws an OOME on large directory structures.

The following typescript demonstrates this problem in a couple of different ways when the function is presented with a directory containing approximately 600,000 files & sub-directories (note: embedded ANSI escape characters have been manually removed from this typescript for clarity):

Script started on Thu Jan  3 22:45:39 2013
bash-3.2$ ls -R /Users/pmonks/Development | wc -l
ls: unreadableDirectory: Permission denied
  614630
bash-3.2$ lein repl
nREPL server started on port 52181
REPL-y 0.1.0-beta10
Clojure 1.4.0
    Exit: Control+D or (exit) or (quit)
Commands: (user/help)
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
          (user/sourcery function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
Examples from clojuredocs.org: [clojuredocs or cdoc]
          (user/clojuredocs name-here)
          (user/clojuredocs "ns-here" "name-here")
fs-scan.core=> (require '[fs.core :as fs])
nil
fs-scan.core=> (defn walker [root dirs files] ())
#'fs-scan.core/walker
fs-scan.core=> (fs/walk walker "/Users/pmonks/Development")�
OutOfMemoryError Java heap space  java.util.Arrays.copyOf (Arrays.java:2882)

fs-scan.core=> (fs/iterate-dir "/Users/pmonks/Development")�
OutOfMemoryError Java heap space  java.util.Arrays.copyOf (Arrays.java:2882)

fs-scan.core=> (do (fs/iterate-dir "/Users/pmonks/Development")� ())
OutOfMemoryError Java heap space  java.util.Arrays.copyOf (Arrays.java:2882)

fs-scan.core=> exit
Bye for now!

bash-3.2$ exit
exit

Script done on Thu Jan  3 22:53:42 2013

I believe this is occurring because iterate-dir is not lazy (despite the doc comment), and is eagerly building the entire sequence of pathnames in memory.

no path join, or separator?

I notice there are operations for splitting paths, but none for joining them. Also, the file separator is not exported (seems like it was in the first announcements of this lib?), so callers will have to independently import File to join paths.

*Cwd* is lost/reset when mapping over a collection

Setup:
Start a clojure repl in namespace fs.core, with current working directory of /home/wordempire
Steps:

(with-cwd "MyTestFolder"
(map (fn [_] *cwd*) (take 4 (repeat 1)))

Expected:

(#<File /home/wordempire/MyTestFolder> #<File /home/wordempire/MyTestFolder> #<File /home/wordempire/MyTestFolder> #<File /home/wordempire/MyTestFolder>)

Instead:

(#<File /home/wordempire> #<File /home/wordempire> #<File /home/wordempire> #<File /home/wordempire>)

concat method?

Is there a way to concat files? I see file copy, but no append or concat.

silly issue getting fs into my project

When requiring fs in ns or explicitly using it I receive an error.

ex:

(ns somens (:require [me.raynes.fs :as fs])
;; or
(use 'me.raynes.fs)

What am I doing wrong?

java.lang.ClassNotFoundException: java.nio.file.Files
at java.net.URLClassLoader$1.run (URLClassLoader.java:217)
java.security.AccessController.doPrivileged (AccessController.java:-2)
java.net.URLClassLoader.findClass (URLClassLoader.java:205)
clojure.lang.DynamicClassLoader.findClass (DynamicClassLoader.java:61)
java.lang.ClassLoader.loadClass (ClassLoader.java:321)
java.lang.ClassLoader.loadClass (ClassLoader.java:266)
java.lang.Class.forName0 (Class.java:-2)
java.lang.Class.forName (Class.java:188)
me.raynes.fs$eval4508$loading__4910__auto____4509.invoke (fs.clj:1)
me.raynes.fs$eval4508.invoke (fs.clj:1)
clojure.lang.Compiler.eval (Compiler.java:6619)
clojure.lang.Compiler.eval (Compiler.java:6608)
clojure.lang.Compiler.load (Compiler.java:7064)
clojure.lang.RT.loadResourceScript (RT.java:370)
clojure.lang.RT.loadResourceScript (RT.java:361)
clojure.lang.RT.load (RT.java:440)
clojure.lang.RT.load (RT.java:411)
clojure.core$load$fn__5018.invoke (core.clj:5530)
clojure.core$load.doInvoke (core.clj:5529)
clojure.lang.RestFn.invoke (RestFn.java:408)
clojure.core$load_one.invoke (core.clj:5336)
clojure.core$load_lib$fn__4967.invoke (core.clj:5375)
clojure.core$load_lib.doInvoke (core.clj:5374)
clojure.lang.RestFn.applyTo (RestFn.java:142)
clojure.core$apply.invoke (core.clj:619)
clojure.core$load_libs.doInvoke (core.clj:5413)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invoke (core.clj:621)
clojure.core$use.doInvoke (core.clj:5507)
clojure.lang.RestFn.invoke (RestFn.java:408)
myrtle.handler$eval4504.invoke (form-init9111875169219397921.clj:1)
clojure.lang.Compiler.eval (Compiler.java:6619)
clojure.lang.Compiler.eval (Compiler.java:6582)
clojure.core$eval.invoke (core.clj:2852)
clojure.main$repl$read_eval_print__6588$fn__6591.invoke (main.clj:259)
clojure.main$repl$read_eval_print__6588.invoke (main.clj:259)
clojure.main$repl$fn__6597.invoke (main.clj:277)
clojure.main$repl.doInvoke (main.clj:277)
clojure.lang.RestFn.invoke (RestFn.java:1096)
clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__3558.invoke (interruptible_eval.clj:56)
clojure.lang.AFn.applyToHelper (AFn.java:159)
clojure.lang.AFn.applyTo (AFn.java:151)
clojure.core$apply.invoke (core.clj:617)
clojure.core$with_bindings_STAR_.doInvoke (core.clj:1788)
clojure.lang.RestFn.invoke (RestFn.java:425)
clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke (interruptible_eval.clj:41)
clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__3599$fn__3602.invoke (interruptible_eval.clj:171)
clojure.core$comp$fn__4154.invoke (core.clj:2330)
clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__3592.invoke (interruptible_eval.clj:138)
clojure.lang.AFn.run (AFn.java:24)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1146)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615)
java.lang.Thread.run (Thread.java:679)

Security vulnerability in dependent library

White source flagged security vulnerability issue in commons-compress:jar:1.8, which is used by me.raynes:fs:jar:1.4.6.

Following is the dependency tree:

+- me.raynes:fs:jar:1.4.6:compile
| +- (org.clojure:clojure:jar:1.4.0:compile
| - (org.apache.commons:commons-compress:jar:1.8:compile)

White source concern:

When reading a specially crafted ZIP archive, the read method of Apache Commons Compress 1.7 to 1.17's ZipArchiveInputStream can fail to return the correct EOF indication after the end of the stream has been reached. When combined with a java.io.InputStreamReader this can lead to an infinite stream, which can be used to mount a denial of service attack against services that use Compress' zip package.

Suggested fix:

I. Upgrade to version 1.18

II. The vendor has issued a fix (1.18).
The vendor advisory is available at:
https://commons.apache.org/proper/commons-compress/security-reports.html#Apache_Commons_Compress_Security_Vulnerabilities

When would I see include-java-7-fns?

This is basically the same as my previous question from 2015. But my question here is about include-java-7-fns.

If I have this in my project.clj:

             [me.raynes/fs "1.4.6"]

And in Emacs I go "nrepl-jack-in" and then:

(require '[me.raynes.fs :as fs])
 
(ns-publics 'me.raynes.fs)

I end up with:

{chdir #'me.raynes.fs/chdir

 read-sym-link #'me.raynes.fs/read-sym-link

 absolute? #'me.raynes.fs/absolute?

 find-files #'me.raynes.fs/find-files

 copy-dir #'me.raynes.fs/copy-dir

 temp-file #'me.raynes.fs/temp-file

 with-mutable-cwd #'me.raynes.fs/with-mutable-cwd

 *cwd* #'me.raynes.fs/*cwd*

 temp-name #'me.raynes.fs/temp-name

 iterate-dir #'me.raynes.fs/iterate-dir

 normalized #'me.raynes.fs/normalized

 child-of? #'me.raynes.fs/child-of?

 tmpdir #'me.raynes.fs/tmpdir

 home #'me.raynes.fs/home

 copy #'me.raynes.fs/copy

 ns-path #'me.raynes.fs/ns-path

 temp-dir #'me.raynes.fs/temp-dir

 parent #'me.raynes.fs/parent

 walk #'me.raynes.fs/walk

 mkdir #'me.raynes.fs/mkdir

 exec #'me.raynes.fs/exec

 mkdirs #'me.raynes.fs/mkdirs

 split-ext #'me.raynes.fs/split-ext

 create #'me.raynes.fs/create

 copy-dir-into #'me.raynes.fs/copy-dir-into

 name #'me.raynes.fs/name

 list-dir #'me.raynes.fs/list-dir

 file #'me.raynes.fs/file

 mod-time #'me.raynes.fs/mod-time

 delete #'me.raynes.fs/delete

 executable? #'me.raynes.fs/executable?

 chmod #'me.raynes.fs/chmod

 rename #'me.raynes.fs/rename

 with-cwd #'me.raynes.fs/with-cwd

 unix-root #'me.raynes.fs/unix-root

 find-files* #'me.raynes.fs/find-files*

 absolute #'me.raynes.fs/absolute

 size #'me.raynes.fs/size

 file? #'me.raynes.fs/file?

 link? #'me.raynes.fs/link?

 extension #'me.raynes.fs/extension

 readable? #'me.raynes.fs/readable?

 expand-home #'me.raynes.fs/expand-home

 split #'me.raynes.fs/split

 writeable? #'me.raynes.fs/writeable?

 delete-dir #'me.raynes.fs/delete-dir

 glob #'me.raynes.fs/glob

 exists? #'me.raynes.fs/exists?

 sym-link #'me.raynes.fs/sym-link

 link #'me.raynes.fs/link

 hidden? #'me.raynes.fs/hidden?

 parents #'me.raynes.fs/parents

 touch #'me.raynes.fs/touch

 path-ns #'me.raynes.fs/path-ns

 copy+ #'me.raynes.fs/copy+

 directory? #'me.raynes.fs/directory?

 base-name #'me.raynes.fs/base-name}

So there is no function called "move".

But if I look here I see a function called "move":

(defn move

But I think "move" should appear if my Java version is 7 or more? On my Mac I have:

java -version
java version "1.8.0_25"

Ultimately, I don't need "move" since I can do "copy" and then "delete" but I'd like to understand why "move" doesn't appear for me.

I just got this error, which caused me to look into this:

java.lang.RuntimeException: No such var: fs/move

copy-dir-into

I found myself implementing this function today, does it or similar belong in your library?

(defn copy-dir-into
  "Copy directory into another directory if destination already exists."
  [from to]
  (if-not (exists? to)
    (copy-dir from to)
    (doseq [name (list-dir from)]
      (let [path (str from name)]
        (if (directory? path)
          (copy-dir path to)
          (copy path (str to name)))))))

Cheers, Dave.

Link to API Docs no longer works

Hello,

First, thank you for creating this library. It is much appreciated. Today I tried to go to the API Docs link that is present on this repo's home page but it does not seem to work anymore. Is there another way to get that documentation?

Regards!

Various tests fail on Windows

Tests depending on absolute paths fail (require drive letter and beginning slash)
Tests depending on file permissions fail (can't remove execute bit)
Tests using ~/ fail (apparently needs ~)
File.toString uses canonical paths

uberjar with java 6 breaks

I like to build apps via uberjar and hand 'em out. ;) Being as I work in a plus struggling to get past Java 6, I can't just require Java 7.

So, I'm wondering if there's a away around the breakage that happens when I "uberjar" a project with this lib in it?

I get:

Caused by: java.lang.ClassNotFoundException: java.nio.file.Path
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:171)
    at me.raynes.fs__init.__init0(Unknown Source)
    at me.raynes.fs__init.<clinit>(Unknown Source)
    ... 133 more

I'm using your lib to zip up a directory, so I can probably rewrite that bit, but....

Any advice?

dirname

I would like to see something that was part of the original fs added back in.

(defn dirname)
"Return directory name of path.\n\t(dirname "a/b/c") -> "/a/b"")
[path])
(.getParent (io/as-file path)))

Ungzip

Write an ungzip function.

Why can I not access some vars that appear in source code for 'me.raynes.fs?

If I look here:

https://github.com/Raynes/fs/blob/master/src/me/raynes/fs.clj

I see vars such as "normalized"

(defn normalized
"Return normalized (canonical) file."
[path](.getCanonicalFile %28file path%29))

and this appears to be public. But if I put this in code I get "no such var". So I double-check myself. I look in project.clj and make sure fs is present:

:dependencies [[org.clojure/clojure "1.5.1"]
[dire "0.5.1"]
[org.clojure/tools.namespace "0.2.4"]
[lamina "0.5.0"]
[me.raynes/fs "1.4.4"]
[org.clojure/core.incubator "0.1.3"]
[clj-time "0.6.0"]]

I also have:

:disable-implicit-clean true

which has sometimes tripped me up in the past, so I carefully run:

lein clean

at the command line. In my own code I have a namespace defined with:

(:require
[me.raynes.fs :as fs]

and in my code I can use:

(fs/exists?)

but this:

(fs/normalized)

and this:

(fs/absolute)

gets me:

Caused by: java.lang.RuntimeException: No such var: fs/absolute, compiling:(tma_make_thumbnails/make_images.clj:56:22)

So I launch the repl and do this:

user> (require '[me.raynes.fs :as fs])

user> (ns-publics 'me.raynes.fs)
{walk #'me.raynes.fs/walk, copy #'me.raynes.fs/copy, readable? #'me.raynes.fs/readable?, create #'me.raynes.fs/create, writeable? #'me.raynes.fs/writeable?, file #'me.raynes.fs/file, split #'me.raynes.fs/split, chmod #'me.raynes.fs/chmod, find-files* #'me.raynes.fs/find-files_, mkdirs #'me.raynes.fs/mkdirs, directory? #'me.raynes.fs/directory?, delete #'me.raynes.fs/delete, tmpdir #'me.raynes.fs/tmpdir, child-of? #'me.raynes.fs/child-of?, sym-link #'me.raynes.fs/sym-link, ns-path #'me.raynes.fs/ns-path, parent #'me.raynes.fs/parent, temp-dir #'me.raynes.fs/temp-dir, file? #'me.raynes.fs/file?, absolute? #'me.raynes.fs/absolute?, mkdir #'me.raynes.fs/mkdir, with-mutable-cwd #'me.raynes.fs/with-mutable-cwd, exec #'me.raynes.fs/exec, link #'me.raynes.fs/link, list-dir #'me.raynes.fs/list-dir, glob #'me.raynes.fs/glob, home #'me.raynes.fs/home, name #'me.raynes.fs/name, parents #'me.raynes.fs/parents, find-files #'me.raynes.fs/find-files, exists? #'me.raynes.fs/exists?, executable? #'me.raynes.fs/executable?, chdir #'me.raynes.fs/chdir, copy-dir #'me.raynes.fs/copy-dir, rename #'me.raynes.fs/rename, temp-name #'me.raynes.fs/temp-name, *cwd_ #'me.raynes.fs/cwd, expand-home #'me.raynes.fs/expand-home, extension #'me.raynes.fs/extension, touch #'me.raynes.fs/touch, copy+ #'me.raynes.fs/copy+, delete-dir #'me.raynes.fs/delete-dir, size #'me.raynes.fs/size, path-ns #'me.raynes.fs/path-ns, split-ext #'me.raynes.fs/split-ext, with-cwd #'me.raynes.fs/with-cwd, hidden? #'me.raynes.fs/hidden?, temp-file #'me.raynes.fs/temp-file, normalized-path #'me.raynes.fs/normalized-path, absolute-path #'me.raynes.fs/absolute-path, unix-root #'me.raynes.fs/unix-root, iterate-dir #'me.raynes.fs/iterate-dir, base-name #'me.raynes.fs/base-name, link? #'me.raynes.fs/link?, mod-time #'me.raynes.fs/mod-time}

Sure enough, there is no "normalized" nor any "absolute".

Why do I see these functions here:

https://github.com/Raynes/fs/blob/master/src/me/raynes/fs.clj

but not in ns-publics?

I look here:

https://github.com/Raynes/fs/blob/master/project.clj

and see the version is:

me.raynes/fs "1.4.5"

but if I go here:

https://github.com/Raynes/fs

I see:

The Most Recent Release
With Leiningen:
[me.raynes/fs "1.4.4"]

so I upgrade to 1.4.5 and run "lein clean" and "lein uberjar" but I still get the same error:

Exception in thread "main" java.lang.RuntimeException: No such var: fs/normalized, compiling:(tma_make_thumbnails/make_images.clj:56:22)

Any suggestions?

touch doesn't set the provided time if it created the file

(fs/touch "meow" (+ (System/currentTimeMillis) 3600000))

Should create a file named meow and set its modification time one hour in the future. If the file is being created, the modification time is just set to the creation time. If we run the same function again, this time not creating the file, the modification time is set properly. Is this intended behavior? It seems like a bug to me.

Regenerate API docs

Current version 1.3.3 is old and misleading because namespaces have changed.

unzip

Write an unzip function

Tests don't run cleanly on Windows

There are a couple of issues when running tests on Windows 7.

As Windows doesn't support symlinks, an exception is thrown:

Exception in thread "main" java.nio.file.FileSystemException: C:\work\fs\test\me\raynes\testfiles\soft.link: A required privilege is not held by the client.

    at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsFileSystemProvider.createSymbolicLink(Unknown Source)
    at java.nio.file.Files.createSymbolicLink(Unknown Source)
    at me.raynes.fs$sym_link.invoke(fs.clj:192)
    at me.raynes.core_test$eval8342$fn__8343$fn__8344.invoke(core_test.clj:357)
    (...)

Two files are left behind by tests:

  • test/me/raynes/testfiles/hard.link (perhaps because of the exception, I didn't investigate further yet)
  • test/me/raynes/testfiles/fro.zip (see #92)

What do you think would be the best approach to fix incompatibilities with Windows? Do you know of any way to check if the OS supports symlinks, or should we just check os.name property?

Extending (fs/mkdir) to create intermediate directories

Hi!

Thanks for this lib, very useful.

I just would like to know if/how to create intermediate directories with (fs/mkdir arg).

Example:

  • existing empty dir "resources/public/stock"
  • (fs/mkdir "resources/public/stock/a/b/c") would create all the required dir (a and b and c)

Similar to the unix shell "mkdir -p"

That would be very helpful.

Many thanks

-- Ben

Audit everything and make sure all behavior is as consistent as possible

Right now behavior of some functions is inconsistent with others. I made the decision when I took over the project that I would, whenever possible, return File objects instead of paths. The purpose of this was to prevent unnecessary creation of file objects just to pull the string paths out and then recreate more File objects later.

The problem is that this doesn't make sense for some functions and they are inconsistent. Some functions it does make sense for don't do it and are also inconsistent. I should carefully audit the library and make behavior consistent. This should, if at all possible, be the last breaking API change before all of fs's users vow to murder my first born.

Comments welcome.

Utility to join components (OS-aware)

Is there a way to join components of a path, for example something like this?

(fs/join "/Users" "michael" "code")
;; => "/Users/michael/code"

It would be similar to Python's os.path.join for reference.

Since most of the functions in this library return Files, i'm not sure how this should work for a non-existent filepath.

clear-dir

Can you add a method to delete all data in folder?

pmap better than map for "walk" for processing images

About this function:

(defn walk
"Lazily walk depth-first over the directory structure starting at
'path' calling 'func' with three arguments [root dirs files].
Returns a sequence of the results."
[func path](map #%28apply func %%29 %28iterate-dir path%29))

If I want to iterate over a directory of images, and generate a thumbnail for those images, then I should use "pmap" rather than "map". I am writing a custom version of this function for myself, but perhaps you could make "map" a variable?

windows driver path problem with glob

hi, i am on win7 and try to call glob:

=>(glob "c:/")
RuntimeException Invalid token: c:/
.* clojure.lang.Util.runtimeException (Util.java:170)
")\n(glob "

<RuntimeException java.lang.RuntimeException: Invalid token: c:/*>

seem to be parsing problem with ">" char by windows promt "c:>" or?

Release?

Any chance of a release? There's been a few nice things added since 2014. In particular, I'd like to have access to chmod-octal in a versioned release.

Support for wildcard in the middle of the path

Currently the glob function expects that if a wildcard exists in the path, it will exist in its very end.
I.E. /some/path/with/wildcard.*

But a path like /another/path/*/with/wildcard is not supported and will always return nil (unless you have a directory named *).

temp-dir loops forever on non-existent java.io.tmpdir

fs/temp-dir loops forever if the java.io.tmpdir directory does not exist.

% JAVA_OPTS="-Djava.io.tmpdir=/tmp/nonexistent" lein repl
user=> (require '[me.raynes.fs :as fs])
nil
user=> (fs/tmpdir)
"/tmp/nonexistent"
user=> (fs/temp-dir "foo")

Pull request forthcoming.

Add a child-of? function

Should check to see if a directory or file is a subdirectory/file of a given path. Name is tentative.

[Suggestion] Add function to fix paths for different OS

I usually face a problem of incorrect paths or part of paths. To fix this, I use the following workaround:

(defn- fix-path [p]
  (if (not (nil? p))
    (if (.startsWith (System/getProperty "os.name") "Windows")
      (string/replace p "/" "\\")
      (string/replace p "\\" "/"))))

Is it possible to put something like this in fs library?

Breadth-first option for fs/walk would be nice

I've encountered a case where I'd like to do a breadth-first traversal of a directory structure, and I don't see a way to do this with fs/walk as it currently stands.

My use case: I have a directory tree full of XML files representing various books and magazine articles. Each one has a cover page, linked to by an img element near the top of the XML file, and I'm trying to present a view to the user that shows some basic metadata: cover image, title, author, that sort of thing. Thing is, while the original directory structure had the cover images in the same directory as the content (and the img element in the XML has a src attribute with no path in it), some kind soul has "helpfully" reorganized the directory structure to collect all the cover images together. And while I could just hard-code the cover image directory into my code, that feels like the wrong solution to me: what if it changes again? I can't be constantly tweaking this code; it needs to Just Work.

So I want to do a fs/walk of the directory structure, starting from the library-root directory, to find the cover images. Thing is, there are several hundred directories in the tree, arranged something like this:

library-root/category1/book001
library-root/category1/book002
library-root/category1/book003
library-root/category2/book001
library-root/category2/book002
library-root/category2/book003
library-root/cover-images

Except it's more like six hundred bookNNN directories, not just six. A breadth-first traversal would find the right directory FAR sooner than a depth-first traversal would.

Unfortunately, I don't have quite enough Clojure expertise at this point to code it myself, or I would just write it and submit a pull request. But I would really like to see a breadth-first option for directory walking.

cwd not thread-safe

when you use fs.core/chdir from different threads concurrently, the single instance of cwd will get updated by all, which makes it kind of indeterministic,,, an alternative would be to make cwd thread-local or maybe inheritable-thread-local is better, but unfortunately that would break backwards compatibility as you would need a double deref "@@cwd" - or maybe there are other solutions (?).
I've forked your fs and implemented a solution based on inheritable-thread-local - didn't want to add a pull request as it breaks backwards compatibility - i'd be happy to contribute it - pls take a look: https://github.com/franks42/fs
(the inheritable-thread-local is based on useful.utils/thread-local but initializes the thread-local value with the parent's thread one).
-Regards, FrankS.

walk needs more doc

I got tripped up by some changes to walk (compared to the pre-1.0 version). The order of the arguments changed, which is fine -- Clojure HOFs should take the function first. The big difference is that walk is now lazy and returns the results of mapping over the directory structure. The old version was called just for side-effects (per dorun). It's not obvious from the doc-string what the walk order is so it's unclear how useful the results would be.

I think walk should document the walk order as depth-first, and add a note that it's lazy. Suggested doc-string:

"Lazily walks depth-first over the directory structure starting at 'path', calling 'func' with three arguments [root dirs files]. Returns a sequence of the results."

Also, the doc-string for iter-dir should say that it's depth-first.

untar

Write an untar function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.