(lockPath string)
| 1574 | } |
| 1575 | |
| 1576 | func runtimeSetLockOwner(lockPath string) (runtimeSetLockOwnerRecord, bool) { |
| 1577 | var empty runtimeSetLockOwnerRecord |
| 1578 | status, err := os.Lstat(lockPath) |
| 1579 | if err != nil || status.Mode()&os.ModeSymlink != 0 || |
| 1580 | (!status.Mode().IsRegular() && !status.IsDir()) { |
| 1581 | return empty, false |
| 1582 | } |
| 1583 | ownerPath := lockPath |
| 1584 | if status.IsDir() { |
| 1585 | ownerPath = filepath.Join(lockPath, runtimeSetLockOwnerFile) |
| 1586 | } |
| 1587 | ownerStatus, err := os.Lstat(ownerPath) |
| 1588 | if err != nil || !ownerStatus.Mode().IsRegular() { |
| 1589 | return empty, false |
| 1590 | } |
| 1591 | ownerFile, err := platformOpenRuntimeSetLockOwner(ownerPath) |
| 1592 | if err != nil { |
| 1593 | return empty, false |
| 1594 | } |
| 1595 | if runtimeSetLockOwnerReadObserver != nil { |
| 1596 | runtimeSetLockOwnerReadObserver() |
| 1597 | } |
| 1598 | data, readErr := io.ReadAll(ownerFile) |
| 1599 | closeErr := ownerFile.Close() |
| 1600 | if readErr != nil || closeErr != nil { |
| 1601 | return empty, false |
| 1602 | } |
| 1603 | var record runtimeSetLockOwnerRecord |
| 1604 | if err := json.Unmarshal(data, &record); err != nil { |
| 1605 | return empty, false |
| 1606 | } |
| 1607 | decoded, decodeErr := hex.DecodeString(record.Token) |
| 1608 | if record.PID <= 0 || record.Token != strings.ToLower(record.Token) || |
| 1609 | decodeErr != nil || len(decoded) != runtimeSetLockTokenSize { |
| 1610 | return empty, false |
| 1611 | } |
| 1612 | return record, true |
| 1613 | } |
| 1614 | |
| 1615 | func runtimeSetSameLockObject(left, right os.FileInfo) bool { |
| 1616 | return left != nil && right != nil && os.SameFile(left, right) && |
no test coverage detected