creates the directory and adds the lock
()
| 521 | |
| 522 | // creates the directory and adds the lock |
| 523 | func (n *Node) openDataDir() error { |
| 524 | if n.config.DataDir == "" { |
| 525 | return nil // ephemeral |
| 526 | } |
| 527 | |
| 528 | instdir := filepath.Join(n.config.DataDir, n.config.name()) |
| 529 | if err := os.MkdirAll(instdir, 0700); err != nil { |
| 530 | return err |
| 531 | } |
| 532 | // lock the instance directory to prevent concurrent use by another instance as well as |
| 533 | // accidental use of the instance directory as a database. |
| 534 | release, _, err := flock.New(filepath.Join(instdir, "LOCK")) |
| 535 | if err != nil { |
| 536 | return convertFileLockError(err) |
| 537 | } |
| 538 | n.instanceDirLock = release |
| 539 | return nil |
| 540 | } |
| 541 | |
| 542 | // InstanceDir retrieves the instance directory used by the protocol stack. |
| 543 | // It resides inside the DataDir. |
no test coverage detected