Skip to content

Commit fbf2d2d

Browse files
Merge pull request #126 from HexmosTech/b2m-v4-migration
B2m v2 migration
2 parents c36e59c + 12c8a72 commit fbf2d2d

25 files changed

Lines changed: 647 additions & 746 deletions

b2-manager/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
build:
2-
go build -o b2m main.go
2+
go build -o b2m main.go

b2-manager/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
3. **b3sum**: Install `b3sum` for fast hashing.
2020
- Rust: `cargo install b3sum`.
2121
- See also: [BLAKE3](https://github.com/BLAKE3-team/BLAKE3?tab=readme-ov-file).
22-
22+
- Download binary (Linux x64):
23+
`curl -L -o b3sum https://github.com/BLAKE3-team/BLAKE3/releases/download/1.8.3/b3sum_linux_x64_bin`
24+
- Make executable & move to path:
25+
`chmod +x b3sum && sudo mv b3sum /usr/local/bin/`
2326
### Installation
2427

2528
1. Move the binary to your `frontend` directory (recommended) or add to `/frontend/`.

b2-manager/config/config.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package config
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"os/user"
78
"path/filepath"
89
"strings"
910

1011
"github.com/BurntSushi/toml"
1112

13+
"b2m/core"
1214
"b2m/model"
1315
)
1416

@@ -41,6 +43,7 @@ func InitializeConfig() error {
4143
model.AppConfig.LocalB2MDir = filepath.Join(model.AppConfig.ProjectRoot, ".b2m")
4244
model.AppConfig.LocalVersionDir = filepath.Join(model.AppConfig.LocalB2MDir, "version")
4345
model.AppConfig.LocalAnchorDir = filepath.Join(model.AppConfig.LocalB2MDir, "local-version")
46+
model.AppConfig.MigrationsDir = filepath.Join(model.AppConfig.ProjectRoot, "b2m-migration")
4447

4548
return nil
4649
}
@@ -124,3 +127,47 @@ func fetchUserDetails() {
124127
model.AppConfig.Hostname = h
125128
}
126129
}
130+
131+
// CheckB3SumAvailability verifies that b3sum is installed and runnable
132+
// CheckB3SumAvailability verifies that b3sum is installed and runnable.
133+
// If not found, it attempts to install it automatically.
134+
func checkB3SumAvailability() error {
135+
path, err := exec.LookPath("b3sum")
136+
if err == nil {
137+
core.LogInfo("b3sum found at: %s", path)
138+
return nil
139+
}
140+
core.LogInfo("b3sum not found.")
141+
return fmt.Errorf(`b3sum is missing. Please install it manually:
142+
143+
1. Download binary (Linux x64):
144+
curl -L -o b3sum https://github.com/BLAKE3-team/BLAKE3/releases/download/1.8.3/b3sum_linux_x64_bin
145+
146+
2. Make executable & move to path:
147+
chmod +x b3sum && sudo mv b3sum /usr/local/bin/
148+
149+
Or use cargo:
150+
cargo install b3sum`)
151+
}
152+
153+
// Cleanup saves the hash cache and closes the logger.
154+
// This should be called (usually deferred) by the main function.
155+
func Cleanup() {
156+
if err := core.SaveHashCache(); err != nil {
157+
core.LogError("Failed to save hash cache: %v", err)
158+
}
159+
core.CloseLogger()
160+
}
161+
162+
func CheckDependencies() error {
163+
if err := checkB3SumAvailability(); err != nil {
164+
return err
165+
}
166+
if err := core.CheckRclone(); err != nil {
167+
return fmt.Errorf("rclone not found or error: %w", err)
168+
}
169+
if !core.CheckRcloneConfig() {
170+
return fmt.Errorf("rclone config not found. Run 'init' or check setup")
171+
}
172+
return nil
173+
}

b2-manager/config/init.go

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"context"
54
"fmt"
65
"os"
76

@@ -24,9 +23,6 @@ func InitSystem() *core.SignalHandler {
2423
os.Exit(1)
2524
}
2625

27-
// Set version
28-
model.AppConfig.ToolVersion = "2.0"
29-
3026
// Load hash cache
3127
if err := core.LoadHashCache(); err != nil {
3228
core.LogInfo("Warning: Failed to load hash cache: %v", err)
@@ -36,130 +32,12 @@ func InitSystem() *core.SignalHandler {
3632
core.LogInfo("RootBucket: %s", model.AppConfig.RootBucket)
3733
core.LogInfo("DiscordWebhookURL: %s", model.AppConfig.DiscordWebhookURL)
3834

39-
// CLI Command Handling
40-
if len(os.Args) > 1 {
41-
command := os.Args[1]
42-
43-
switch command {
44-
case "--help":
45-
printUsage()
46-
// We exit here because help is a standalone command
47-
os.Exit(0)
48-
49-
case "--version":
50-
fmt.Printf("b2m version %s\n", model.AppConfig.ToolVersion)
51-
os.Exit(0)
52-
53-
case "--generate-hash":
54-
// Common Dependencies check
55-
if err := checkDependencies(); err != nil {
56-
fmt.Printf("Error: %v\n", err)
57-
os.Exit(1)
58-
}
59-
60-
// Warning and Confirmation
61-
fmt.Println("\nWARNING: This operation regenerates all metadata from local files.")
62-
fmt.Println("Ensure your local databases are synced with remote to avoid data loss.")
63-
fmt.Println("This should ONLY be done when changing hashing algorithms or recovering from corruption.")
64-
fmt.Print("\nAre you sure you want to proceed? (y/N): ")
65-
66-
var confirmation string
67-
fmt.Scanln(&confirmation)
68-
if confirmation != "y" && confirmation != "Y" {
69-
fmt.Println("Operation cancelled.")
70-
os.Exit(0)
71-
}
72-
73-
// Clean up .b2m before generating metadata
74-
if err := core.CleanupLocalMetadata(); err != nil {
75-
fmt.Printf("Error: failed to cleanup metadata: %v\n", err)
76-
core.LogError("Generate-Hash: Failed to cleanup metadata: %v", err)
77-
os.Exit(1)
78-
}
79-
80-
// Explicitly clear hash cache
81-
core.ClearHashCache()
82-
83-
// Bootstrap system minimal
84-
// Use background context for CLI tool mode
85-
cliCtx := context.Background()
86-
if err := core.BootstrapSystem(cliCtx); err != nil {
87-
core.LogError("Startup Warning: %v", err)
88-
}
89-
core.HandleBatchMetadataGeneration()
90-
Cleanup()
91-
os.Exit(0)
92-
93-
case "--reset":
94-
fmt.Println("Resetting system state...")
95-
// Clean up .b2m before starting normal execution
96-
if err := core.CleanupLocalMetadata(); err != nil {
97-
fmt.Printf("Error: failed to cleanup metadata: %v\n", err)
98-
core.LogError("Reset: Failed to cleanup metadata: %v", err)
99-
os.Exit(1)
100-
}
101-
102-
// Explicitly clear hash cache
103-
core.ClearHashCache()
104-
105-
Cleanup()
106-
fmt.Println("Reset complete. Please restart the application.")
107-
os.Exit(0)
108-
109-
default:
110-
fmt.Printf("Unknown command: %s\n", command)
111-
printUsage()
112-
os.Exit(1)
113-
}
114-
}
115-
11635
// Setup cancellation handling
11736
sigHandler := core.NewSignalHandler()
11837

119-
// Startup checks for TUI
120-
if err := checkDependencies(); err != nil {
121-
core.LogError("Startup Error: %v", err)
122-
fmt.Printf("Startup Error: %v\n", err)
123-
os.Exit(1)
124-
}
125-
12638
if err := core.BootstrapSystem(sigHandler.Context()); err != nil {
12739
core.LogError("Startup Warning: %v", err)
12840
}
12941

13042
return sigHandler
13143
}
132-
133-
// Cleanup saves the hash cache and closes the logger.
134-
// This should be called (usually deferred) by the main function.
135-
func Cleanup() {
136-
if err := core.SaveHashCache(); err != nil {
137-
core.LogError("Failed to save hash cache: %v", err)
138-
}
139-
core.CloseLogger()
140-
}
141-
142-
func checkDependencies() error {
143-
if err := core.CheckB3SumAvailability(); err != nil {
144-
return err
145-
}
146-
if err := core.CheckRclone(); err != nil {
147-
return fmt.Errorf("rclone not found or error: %w", err)
148-
}
149-
if !core.CheckRcloneConfig() {
150-
return fmt.Errorf("rclone config not found. Run 'init' or check setup")
151-
}
152-
return nil
153-
}
154-
155-
func printUsage() {
156-
fmt.Println("b2-manager - Backblaze B2 Database Manager")
157-
fmt.Println("\nUsage:")
158-
fmt.Println(" b2-manager [command]")
159-
fmt.Println("\nCommands:")
160-
fmt.Println(" --help Show this help message")
161-
fmt.Println(" --version Show version information")
162-
fmt.Println(" --generate-hash Generate new hash and create metadata in remote")
163-
fmt.Println(" --reset Remove local metadata caches and start fresh UI session")
164-
fmt.Println("\nIf no command is provided, the TUI application starts normally.")
165-
}

b2-manager/core/errors.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

b2-manager/core/handleFiles.go

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)