Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network specific storage paths #149

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ class LightningNodeService {
self.keyService = keyService

var config = defaultConfig()
config.storageDirPath = FileManager.default.getDocumentsDirectoryPath()
config.logDirPath = FileManager.default.getDocumentsDirectoryPath()
config.storageDirPath = FileManager.default.getDocumentsDirectoryPath().appending(
"/\(network.description)/"
)
config.logDirPath = FileManager.default.getDocumentsDirectoryPath().appending(
"/\(network.description)/"
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ensure proper directory handling for network-specific paths.

While the network-specific paths align with the PR objective, there are a few improvements needed:

  1. The code should ensure directories exist before use
  2. Use URL path components instead of string concatenation for robust path handling
  3. Consider data migration strategy for network switching

Here's a safer implementation:

-        config.storageDirPath = FileManager.default.getDocumentsDirectoryPath().appending(
-            "/\(network.description)/"
-        )
-        config.logDirPath = FileManager.default.getDocumentsDirectoryPath().appending(
-            "/\(network.description)/"
-        )
+        let documentsPath = FileManager.default.getDocumentsDirectoryPath()
+        let networkPath = URL(fileURLWithPath: documentsPath)
+            .appendingPathComponent(network.description)
+            .path
+        
+        try? FileManager.default.createDirectory(
+            atPath: networkPath,
+            withIntermediateDirectories: true
+        )
+        
+        config.storageDirPath = networkPath
+        config.logDirPath = networkPath
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
config.storageDirPath = FileManager.default.getDocumentsDirectoryPath().appending(
"/\(network.description)/"
)
config.logDirPath = FileManager.default.getDocumentsDirectoryPath().appending(
"/\(network.description)/"
)
let documentsPath = FileManager.default.getDocumentsDirectoryPath()
let networkPath = URL(fileURLWithPath: documentsPath)
.appendingPathComponent(network.description)
.path
try? FileManager.default.createDirectory(
atPath: networkPath,
withIntermediateDirectories: true
)
config.storageDirPath = networkPath
config.logDirPath = networkPath

config.network = self.network
config.trustedPeers0conf = [
Constants.Config.LiquiditySourceLsps2.Signet.lqwd.nodeId
Expand Down