Skip to content

Commit 5689f57

Browse files
committed
removed unused and rsolved maxsize for ipfs
1 parent c4f0357 commit 5689f57

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

blox.test.exe

-44.5 MB
Binary file not shown.

initipfs

-10.5 MB
Binary file not shown.

initipfscluster

-9.23 MB
Binary file not shown.

modules/initipfs/main.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -295,47 +295,48 @@ func readConfigYAML(path string) ConfigYAML {
295295
func readIPFSConfig(sourceIpfsConfig, path string) (IPFSConfig, error) {
296296
var cfg IPFSConfig
297297

298-
// Check if the file exists
298+
// Check if the deployed config file exists
299299
fileInfo, err := os.Stat(path)
300300
if err != nil {
301301
if os.IsNotExist(err) {
302-
// File doesn't exist, return an error to handle in main
303302
return cfg, err
304-
} else {
305-
// Unexpected error, panic
306-
panic(fmt.Sprintf("Failed to check IPFS config file: %v", err))
307303
}
304+
panic(fmt.Sprintf("Failed to check IPFS config file: %v", err))
308305
}
309306

310-
// Check if the target is a directory
307+
// If path is a directory, remove it and fall back to template
311308
if fileInfo.IsDir() {
312-
// Target is a directory, attempt to delete it
313-
err := os.RemoveAll(path)
314-
if err != nil {
315-
// Failed to delete directory, return an error
309+
if err := os.RemoveAll(path); err != nil {
316310
return cfg, fmt.Errorf("failed to delete directory at %s: %v", path, err)
317311
}
318312
if err := copyDefaultIPFSConfig(sourceIpfsConfig, path); err != nil {
319-
panic(fmt.Sprintf("Failed to create empty config file: %v", err))
313+
panic(fmt.Sprintf("Failed to create config file from template: %v", err))
314+
}
315+
}
316+
317+
// Read the DEPLOYED config first (preserves runtime changes like StorageMax)
318+
data, err := os.ReadFile(path)
319+
if err == nil && len(data) > 0 {
320+
if err := json.Unmarshal(data, &cfg); err == nil {
321+
return cfg, nil
320322
}
323+
// Deployed config is corrupt — fall through to template
324+
fmt.Printf("Warning: deployed config %s is corrupt, falling back to template\n", path)
321325
}
322326

323-
// Read the existing file
324-
data, err := os.ReadFile(sourceIpfsConfig)
327+
// Fallback: read from template
328+
data, err = os.ReadFile(sourceIpfsConfig)
325329
if err != nil {
326-
panic(fmt.Sprintf("Failed to read IPFS config: %v", err))
327-
} else if len(data) == 0 {
328-
// File is empty, return an empty struct and nil error
330+
panic(fmt.Sprintf("Failed to read IPFS template config: %v", err))
331+
}
332+
if len(data) == 0 {
329333
return cfg, nil
330-
} else {
331-
// Unmarshal only if the file has content
332-
if err := json.Unmarshal(data, &cfg); err != nil {
333-
// Unmarshaling failed, replace file with empty one and return empty cfg
334-
if err := createEmptyFile(path); err != nil {
335-
return cfg, err
336-
}
337-
return cfg, nil
334+
}
335+
if err := json.Unmarshal(data, &cfg); err != nil {
336+
if err := createEmptyFile(path); err != nil {
337+
return cfg, err
338338
}
339+
return cfg, nil
339340
}
340341
return cfg, nil
341342
}

0 commit comments

Comments
 (0)