mirror of
https://github.com/luxfi/kms.git
synced 2026-10-30 16:23:36 +00:00
Squashes all pre-rewrite history into a single root commit. Previous tree: - 14506 commits including upstream Infisical fork history - Multiple merge chains carrying pre-purge content Force-rewrite per disk-space reclamation discipline. GHCR images (1.9.9, 1.9.11) remain immutable; their git lineage is no longer materialized.
27 lines
720 B
Go
27 lines
720 B
Go
/*
|
|
* SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package z
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// Truncate would truncate the mmapped file to the given size. On Linux, we truncate
|
|
// the underlying file and then call mremap, but on other systems, we unmap first,
|
|
// then truncate, then re-map.
|
|
func (m *MmapFile) Truncate(maxSz int64) error {
|
|
if err := m.Sync(); err != nil {
|
|
return fmt.Errorf("while sync file: %s, error: %v\n", m.Fd.Name(), err)
|
|
}
|
|
if err := m.Fd.Truncate(maxSz); err != nil {
|
|
return fmt.Errorf("while truncate file: %s, error: %v\n", m.Fd.Name(), err)
|
|
}
|
|
|
|
var err error
|
|
m.Data, err = mremap(m.Data, int(maxSz)) // Mmap up to max size.
|
|
return err
|
|
}
|