github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/filenames.go (about) 1 // Copyright 2012 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package pebble 6 7 import ( 8 "fmt" 9 10 "github.com/petermattis/pebble/internal/base" 11 "github.com/petermattis/pebble/vfs" 12 ) 13 14 type fileType = base.FileType 15 16 const ( 17 fileTypeLog = base.FileTypeLog 18 fileTypeLock = base.FileTypeLock 19 fileTypeTable = base.FileTypeTable 20 fileTypeManifest = base.FileTypeManifest 21 fileTypeCurrent = base.FileTypeCurrent 22 fileTypeOptions = base.FileTypeOptions 23 ) 24 25 func setCurrentFile(dirname string, fs vfs.FS, fileNum uint64) error { 26 newFilename := base.MakeFilename(dirname, fileTypeCurrent, fileNum) 27 oldFilename := fmt.Sprintf("%s.%06d.dbtmp", newFilename, fileNum) 28 fs.Remove(oldFilename) 29 f, err := fs.Create(oldFilename) 30 if err != nil { 31 return err 32 } 33 if _, err := fmt.Fprintf(f, "MANIFEST-%06d\n", fileNum); err != nil { 34 return err 35 } 36 if err := f.Sync(); err != nil { 37 return err 38 } 39 if err := f.Close(); err != nil { 40 return err 41 } 42 return fs.Rename(oldFilename, newFilename) 43 }