Skip to content
This repository was archived by the owner on Nov 10, 2024. It is now read-only.

Commit e3bd2ee

Browse files
authored
Merge pull request #74 from ckipp01/archive
feat: add in an archive directory for deleted contexts
2 parents d0aa53f + 03c6099 commit e3bd2ee

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

skan/src/Config.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ object Config:
2626
private val configDir = projectDirs.configDir
2727
private lazy val defaultDataDir = os.Path(dataDir) / "contexts"
2828
val configFile = os.Path(configDir) / "config.json"
29+
val archiveDir = os.Path(dataDir) / "archive"
2930

3031
private def fromJson(json: String) =
3132
upickle.default.read[Config](json)

skan/src/ContextState.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package skan
22

3+
import java.time.Instant
4+
35
/** The top level state of the application containing all of the various
46
* contexts. For most operations that have to do with the selected board this
57
* just acts as a facilators and calls the correct operation on the the correct
@@ -109,8 +111,8 @@ case class ContextState(
109111

110112
def addContext(name: String, boardOrder: Order): ContextState =
111113
this.copy(
112-
boards =
113-
boards.updated(name, BoardState.fromItems(Vector.empty, boardOrder)),
114+
boards = boards
115+
.updated(name, BoardState.fromItems(Vector.empty, boardOrder)),
114116
activeContext = name
115117
)
116118

@@ -123,7 +125,14 @@ case class ContextState(
123125
* The new state
124126
*/
125127
def deleteContext(config: Config): ContextState =
126-
os.remove(config.dataDir / s"${activeContext}.json")
128+
val file = config.dataDir / s"${activeContext}.json"
129+
if os.exists(file) then
130+
os.move(
131+
from = config.dataDir / s"${activeContext}.json",
132+
to =
133+
Config.archiveDir / s"${Instant.now().toString()}-${activeContext}.json",
134+
createFolders = true
135+
)
127136
val newBoards = boards.removed(activeContext)
128137
if newBoards.isEmpty then ContextState.fromConfig(config)
129138
else

0 commit comments

Comments
 (0)