Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 317c799

Browse files
committed
Fix file system actor once again and hopefully for the last time
1 parent 7e6c4dd commit 317c799

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/main/scala/org/codeoverflow/chatoverflow/connector/actor/FileSystemActor.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ class FileSystemActor extends Actor {
3030
override def receive: Receive = {
3131
case LoadFile(pathInResources) =>
3232
try {
33-
sender ! Some(Source.fromFile(s"$dataFilePath${fixPath(pathInResources)}").mkString)
33+
sender ! Some(Source.fromFile(new File(dataFolder, pathInResources)).mkString)
3434
} catch {
3535
case _: Exception => None
3636
}
3737
case LoadBinaryFile(pathInResources) =>
3838
try {
39-
sender ! Files.readAllBytes(new File(s"$dataFilePath${fixPath(pathInResources)}").toPath)
39+
sender ! Some(Files.readAllBytes(new File(dataFolder, pathInResources).toPath))
4040
} catch {
41-
case _: Exception => Array[Byte]()
41+
case e: Exception => e.printStackTrace()
42+
None
4243
}
4344
case SaveFile(pathInResources, content) =>
4445
try {
45-
val writer = new PrintWriter(s"$dataFilePath${fixPath(pathInResources)}")
46+
val writer = new PrintWriter(new File(dataFolder, pathInResources))
4647
writer.write(content)
4748
writer.close()
4849
sender ! true
@@ -51,23 +52,18 @@ class FileSystemActor extends Actor {
5152
}
5253
case SaveBinaryFile(pathInResources, content) =>
5354
try {
54-
Files.write(new File(s"$dataFilePath${fixPath(pathInResources)}").toPath, content)
55+
Files.write(new File(dataFolder, pathInResources).toPath, content)
5556
sender ! true
5657
} catch {
5758
case _: Exception => sender ! false
5859
}
5960
case CreateDirectory(folderName) =>
6061
try {
61-
sender ! new File(s"$dataFilePath${fixPath(folderName)}").mkdir()
62+
sender !new File(dataFolder, folderName).mkdir()
6263
} catch {
6364
case _: Exception => sender ! false
6465
}
6566
}
66-
67-
private def fixPath(path: String): String = {
68-
val fixedPath = Paths.get(File.separator, path).normalize()
69-
fixedPath.toString
70-
}
7167
}
7268

7369
object FileSystemActor {

0 commit comments

Comments
 (0)