lib/fs: rename MustWriteFileAndSync to MustWriteSync in order to improve readability a bit

This is a follow-up for 2a8395be05
This commit is contained in:
Aliaksandr Valialkin 2023-04-13 21:42:11 -07:00
parent b15c5961ab
commit 344209e5e6
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
5 changed files with 13 additions and 13 deletions

View file

@ -25,7 +25,7 @@ func MustSyncPath(path string) {
mustSyncPath(path)
}
// MustWriteFileAndSync writes data to the file at path and then calls fsync on the created file.
// MustWriteSync writes data to the file at path and then calls fsync on the created file.
//
// The fsync guarantees that the written data survives hardware reset after successful call.
//
@ -33,7 +33,7 @@ func MustSyncPath(path string) {
// in the middle of the write.
// Use WriteFileAtomically if the file at the path must be either written in full
// or not written at all on app crash in the middle of the write.
func MustWriteFileAndSync(path string, data []byte) {
func MustWriteSync(path string, data []byte) {
f, err := filestream.Create(path, false)
if err != nil {
logger.Panicf("FATAL: cannot create file: %s", err)
@ -69,7 +69,7 @@ func WriteFileAtomically(path string, data []byte, canOverwrite bool) error {
// Write data to a temporary file.
n := atomic.AddUint64(&tmpFileNum, 1)
tmpPath := fmt.Sprintf("%s.tmp.%d", path, n)
MustWriteFileAndSync(tmpPath, data)
MustWriteSync(tmpPath, data)
// Atomically move the temporary file from tmpPath to path.
if err := os.Rename(tmpPath, path); err != nil {

View file

@ -38,16 +38,16 @@ func (mp *inmemoryPart) StoreToDisk(path string) error {
return fmt.Errorf("cannot create directory %q: %w", path, err)
}
metaindexPath := filepath.Join(path, metaindexFilename)
fs.MustWriteFileAndSync(metaindexPath, mp.metaindexData.B)
fs.MustWriteSync(metaindexPath, mp.metaindexData.B)
indexPath := filepath.Join(path, indexFilename)
fs.MustWriteFileAndSync(indexPath, mp.indexData.B)
fs.MustWriteSync(indexPath, mp.indexData.B)
itemsPath := filepath.Join(path, itemsFilename)
fs.MustWriteFileAndSync(itemsPath, mp.itemsData.B)
fs.MustWriteSync(itemsPath, mp.itemsData.B)
lensPath := filepath.Join(path, lensFilename)
fs.MustWriteFileAndSync(lensPath, mp.lensData.B)
fs.MustWriteSync(lensPath, mp.lensData.B)
mp.ph.MustWriteMetadata(path)

View file

@ -128,5 +128,5 @@ func (ph *partHeader) MustWriteMetadata(partPath string) {
// There is no need in calling fs.WriteFileAtomically() here,
// since the file is created only once during part creatinng
// and the part directory is synced aftewards.
fs.MustWriteFileAndSync(metadataPath, metadata)
fs.MustWriteSync(metadataPath, metadata)
}

View file

@ -41,16 +41,16 @@ func (mp *inmemoryPart) StoreToDisk(path string) error {
return fmt.Errorf("cannot create directory %q: %w", path, err)
}
timestampsPath := filepath.Join(path, timestampsFilename)
fs.MustWriteFileAndSync(timestampsPath, mp.timestampsData.B)
fs.MustWriteSync(timestampsPath, mp.timestampsData.B)
valuesPath := filepath.Join(path, valuesFilename)
fs.MustWriteFileAndSync(valuesPath, mp.valuesData.B)
fs.MustWriteSync(valuesPath, mp.valuesData.B)
indexPath := filepath.Join(path, indexFilename)
fs.MustWriteFileAndSync(indexPath, mp.indexData.B)
fs.MustWriteSync(indexPath, mp.indexData.B)
metaindexPath := filepath.Join(path, metaindexFilename)
fs.MustWriteFileAndSync(metaindexPath, mp.metaindexData.B)
fs.MustWriteSync(metaindexPath, mp.metaindexData.B)
mp.ph.MustWriteMetadata(path)

View file

@ -174,5 +174,5 @@ func (ph *partHeader) MustWriteMetadata(partPath string) {
// There is no need in calling fs.WriteFileAtomically() here,
// since the file is created only once during part creatinng
// and the part directory is synced aftewards.
fs.MustWriteFileAndSync(metadataPath, metadata)
fs.MustWriteSync(metadataPath, metadata)
}