Skip to content

Commit 97c2124

Browse files
bdmendesafonsoafonsoafonso
authored andcommitted
Remove unnecessary FileDescriptor overrides
1 parent b21494c commit 97c2124

5 files changed

Lines changed: 8 additions & 58 deletions

File tree

modules/io/src/main/scala/com/kevel/apso/io/FileDescriptor.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ trait FileDescriptor {
8686
* @return
8787
* an iterator with the lines of this file.
8888
*/
89-
def lines(): Iterator[String] = Source.fromInputStream(stream()).getLines()
89+
final def lines(): Iterator[String] = Source.fromInputStream(stream()).getLines()
9090

9191
/** Returns true if the fd points to a directory
9292
* @return
@@ -130,15 +130,15 @@ trait FileDescriptor {
130130
* @return
131131
* the new file descriptor with the updated path
132132
*/
133-
def /(name: String): Self = child(name)
133+
final def /(name: String): Self = child(name)
134134

135135
/** Adds multiple new child nodes to the filesystem path.
136136
* @param names
137137
* the node names to add.
138138
* @return
139139
* the new file descriptor with the updated path
140140
*/
141-
def children(names: String*): Self =
141+
final def children(names: String*): Self =
142142
names.foldLeft(this.asInstanceOf[Self])((acc, c) => acc.child(c).asInstanceOf[Self])
143143

144144
/** Changes the path of the file descriptor using unix's cd syntax related to the current directory.
@@ -154,7 +154,7 @@ trait FileDescriptor {
154154
* @return
155155
* the new file descriptor with the updated path
156156
*/
157-
def cd(pathString: String): Self = {
157+
final def cd(pathString: String): Self = {
158158
pathString.split("/").toList.foldLeft(this.asInstanceOf[Self]) {
159159
case (acc, "." | "") => acc
160160
case (acc, "..") => acc.parent().asInstanceOf[Self]
@@ -168,15 +168,15 @@ trait FileDescriptor {
168168
* @return
169169
* a new file descriptor pointing to a sibling of the current file descriptor
170170
*/
171-
def sibling(name: String): Self = sibling(_ => name)
171+
final def sibling(name: String): Self = sibling(_ => name)
172172

173173
/** Returns a new file descriptor pointing to a sibling of the current file descriptor
174174
* @param f
175175
* a function that returns a new name from the current name of the file descriptor
176176
* @return
177177
* a new file descriptor pointing to a sibling of the current file descriptor
178178
*/
179-
def sibling(f: String => String): Self = parent().child(f(name)).asInstanceOf[Self]
179+
final def sibling(f: String => String): Self = parent().child(f(name)).asInstanceOf[Self]
180180

181181
/** Returns true if the file pointed by the file descriptor exists
182182
* @return

modules/io/src/main/scala/com/kevel/apso/io/GCSFileDescriptor.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ case class GCSFileDescriptor(
6161

6262
def stream(offset: Long = 0L): InputStream = bucket.stream(builtPath, offset)
6363

64-
override def cd(pathString: String): GCSFileDescriptor = {
65-
val newPath = pathString.split("/").map(_.trim).toList.foldLeft(elements) {
66-
case (acc, "." | "") => acc
67-
case (acc, "..") => acc.dropRight(1)
68-
case (acc, segment) => acc :+ segment
69-
}
70-
this.copy(elements = newPath)
71-
}
72-
7364
override def list: Iterator[GCSFileDescriptor] = {
7465
val prefix = elements.mkString("/")
7566
bucket
@@ -85,9 +76,6 @@ case class GCSFileDescriptor(
8576
}
8677
}
8778

88-
override def sibling(f: String => String): GCSFileDescriptor =
89-
GCSFileDescriptor(bucket, elements.dropRight(1) :+ f(name))
90-
9179
private lazy val isDirectoryRemote: Boolean =
9280
elements.isEmpty || bucket.isDirectory(builtPath)
9381

modules/io/src/main/scala/com/kevel/apso/io/LocalFileDescriptor.scala

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,11 @@ case class LocalFileDescriptor(initialPath: String) extends FileDescriptor with
4545
LocalFileDescriptor(parentPath.toString)
4646
}
4747

48-
override def /(name: String): LocalFileDescriptor = child(name)
49-
5048
def child(name: String): LocalFileDescriptor = {
5149
val childPath = normalizedPath.resolve(name)
5250
LocalFileDescriptor(childPath.toString)
5351
}
5452

55-
override def children(names: String*): LocalFileDescriptor = {
56-
val childPath = names.foldLeft(normalizedPath) { (acc, child) =>
57-
acc.resolve(child)
58-
}
59-
LocalFileDescriptor(childPath.toString)
60-
}
61-
62-
override def cd(pathString: String): LocalFileDescriptor = {
63-
val newPath = pathString.split("/").map(_.trim).toList.foldLeft(normalizedPath) {
64-
case (acc, "." | "") => acc
65-
case (acc, "..") => acc.getParent
66-
case (acc, segment) => acc.resolve(segment)
67-
}
68-
LocalFileDescriptor(newPath.toString)
69-
}
70-
7153
def download(localTarget: LocalFileDescriptor, safeDownloading: Boolean): Boolean = {
7254
if (isDirectory || localTarget.isDirectory) {
7355
throw new Exception("File descriptor points to a directory")
@@ -157,10 +139,6 @@ case class LocalFileDescriptor(initialPath: String) extends FileDescriptor with
157139

158140
def exists: Boolean = file.exists()
159141

160-
override def sibling(f: String => String): LocalFileDescriptor = {
161-
LocalFileDescriptor(normalizedPath.resolveSibling(f(name)).toString)
162-
}
163-
164142
def delete(): Boolean = file.delete()
165143

166144
/** Deletes the directory associated with the file descriptor by recursively deleting all the directories and files

modules/io/src/main/scala/com/kevel/apso/io/RemoteFileDescriptor.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ trait RemoteFileDescriptor { this: FileDescriptor =>
2525

2626
protected def duplicate(elements: List[String]): Self
2727

28-
def parent(n: Int = 1): Self =
28+
final def parent(n: Int = 1): Self =
2929
this.duplicate(elements = elements.dropRight(n))
3030

31-
def child(name: String): Self =
31+
final def child(name: String): Self =
3232
this.duplicate(elements = elements ++ sanitize(name).toList)
33-
34-
override def children(names: String*): Self =
35-
this.duplicate(elements = elements ++ names.flatMap(sanitize))
3633
}

modules/io/src/main/scala/com/kevel/apso/io/S3FileDescriptor.scala

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ case class S3FileDescriptor(
7777

7878
def stream(offset: Long = 0L) = bucket.stream(builtPath, offset)
7979

80-
override def cd(pathString: String): S3FileDescriptor = {
81-
val newPath = pathString.split("/").map(_.trim).toList.foldLeft(elements) {
82-
case (acc, "." | "") => acc
83-
case (acc, "..") => acc.dropRight(1)
84-
case (acc, segment) => acc :+ segment
85-
}
86-
this.copy(elements = newPath)
87-
}
88-
8980
override def list: Iterator[S3FileDescriptor] = {
9081
val prefix = elements.mkString("/")
9182
bucket
@@ -105,10 +96,6 @@ case class S3FileDescriptor(
10596
bucket.getObjectsWithMatchingPrefix(buildPath(elements :+ prefix), includeDirectories)
10697
}
10798

108-
override def sibling(f: String => String): S3FileDescriptor = {
109-
S3FileDescriptor(bucket, elements.dropRight(1) :+ f(name))
110-
}
111-
11299
private lazy val isDirectoryRemote = {
113100
// the bucket itself is considered a directory
114101
if (elements.isEmpty) true

0 commit comments

Comments
 (0)