Skip to content

Commit 94098fb

Browse files
committed
join-paths function added and used instead of str in storage.clj
1 parent c7fec94 commit 94098fb

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/clj/backtype/storm/nimbus/storage.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
(log-message "Using default storage (" stormroot ")")
1212
(reify INimbusStorage
1313
(^InputStream open [this, ^String path]
14-
(FileInputStream. (str stormroot path)))
14+
(FileInputStream. (join-paths stormroot path)))
1515

1616
(^OutputStream create [this, ^String path]
17-
(FileOutputStream. (str stormroot path)))
17+
(FileOutputStream. (join-paths stormroot path)))
1818

1919
(^List list [this, ^String path]
20-
(seq (.list (File. (str stormroot path)))))
20+
(seq (.list (File. (join-paths stormroot path)))))
2121

2222
(^void delete [this, ^String path]
23-
(let [full-path (str stormroot path)]
23+
(let [full-path (join-paths stormroot path)]
2424
(when (exists-file? full-path)
2525
(FileUtils/forceDelete (File. full-path)))))
2626

2727
(^void mkdirs [this, ^String path]
28-
(FileUtils/forceMkdir (File. (str stormroot path))))
28+
(FileUtils/forceMkdir (File. (join-paths stormroot path))))
2929

3030
(^boolean isSupportDistributed [this]
3131
false))))

src/clj/backtype/storm/util.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,3 +813,14 @@
813813
(let [klass (if (string? klass) (Class/forName klass) klass)]
814814
(.newInstance klass)
815815
))
816+
817+
(defn join-paths [^String left ^String right]
818+
(let [l-slash (= \/ (last left))
819+
r-slash (= \/ (first right))]
820+
(if (and l-slash r-slash)
821+
(let [right (.substring right 1)]
822+
(str left right))
823+
(if-not (or l-slash r-slash)
824+
(str left "/" right)
825+
(str left right)))))
826+

0 commit comments

Comments
 (0)