Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup #414

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions .github/template/generate_page/action.yml

This file was deleted.

6 changes: 3 additions & 3 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (opt *mountOptions) validate(skipNonEmptyMount bool) error {

if err != nil && os.IsNotExist(err) {
// create the default work dir
if err = os.MkdirAll(common.ExpandPath(common.DefaultWorkDir), 0777); err != nil {
if err = os.MkdirAll(common.ExpandPath(common.DefaultWorkDir), 0755); err != nil {
return fmt.Errorf("failed to create default work dir [%s]", err.Error())
}
}
Expand Down Expand Up @@ -526,8 +526,8 @@ var mountCmd = &cobra.Command{
pid := os.Getpid()
fname := fmt.Sprintf("/tmp/cloudfuse.%v", pid)

ctx, _ := context.WithCancel(context.Background()) //nolint
err = createDaemon(pipeline, ctx, pidFileName, 0644, 027, fname)
ctx := context.Background()
err = createDaemon(pipeline, ctx, pidFileName, 0644, 022, fname)
if err != nil {
return fmt.Errorf("mount: failed to create daemon [%v]", err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import (
func createDaemon(pipeline *internal.Pipeline, ctx context.Context, pidFileName string, pidFilePerm os.FileMode, umask int, fname string) error {
dmnCtx := &daemon.Context{
PidFileName: pidFileName,
PidFilePerm: 0644,
Umask: 022,
PidFilePerm: pidFilePerm,
Umask: umask,
LogFileName: fname, // this will redirect stderr of child to given file
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func decryptConfigFile(saveConfig bool) ([]byte, error) {

// saveToFile: Save the newly generated config file and delete the source if requested
func saveToFile(configFileName string, data []byte, deleteSource bool) error {
err := os.WriteFile(configFileName, data, 0777)
err := os.WriteFile(configFileName, data, 0644)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/secure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (suite *secureConfigTestSuite) TestSecureConfigDecrypt() {
// Config file should be deleted
suite.assert.NoFileExists(confFile.Name())

_, err = executeCommandSecure(rootCmd, "secure", "decrypt", fmt.Sprintf("--config-file=%s", outFile.Name()), "--passphrase=12312312312312312312312312312312", fmt.Sprintf("--output-file=./tmp.yaml"))
_, err = executeCommandSecure(rootCmd, "secure", "decrypt", fmt.Sprintf("--config-file=%s", outFile.Name()), "--passphrase=12312312312312312312312312312312", "--output-file=./tmp.yaml")
suite.assert.NoError(err)

data, err := os.ReadFile("./tmp.yaml")
Expand Down
2 changes: 2 additions & 0 deletions common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (suite *ConfigTestSuite) TestOverlapShadowConfigReader() {
templAppFlag.Changed = true
BindPFlag("template.metadata.labels.app", templAppFlag)
err = os.Setenv("CF_TEST_TEMPLABELS_APP", "somethingthatshouldnotshowup")
assert.NoError(err)
BindEnv("template.metadata.labels.app", "CF_TEST_TEMPLABELS_APP")

err = ReadConfigFromReader(strings.NewReader(specconf))
Expand Down Expand Up @@ -306,6 +307,7 @@ func (suite *ConfigTestSuite) TestPlainConfig1Reader() {
}{}

err = Unmarshal(&randOpts)
assert.NoError(err)
assert.Empty(randOpts)
}

Expand Down
4 changes: 2 additions & 2 deletions component/block_cache/block_cache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ func (bc *BlockCache) download(item *workItem) {
item.block.endIndex = item.block.offset + uint64(n)

if bc.tmpPath != "" {
err := os.MkdirAll(filepath.Dir(localPath), 0777)
err := os.MkdirAll(filepath.Dir(localPath), 0755)
if err != nil {
log.Err("BlockCache::download : error creating directory structure for file %s [%s]", localPath, err.Error())
return
Expand Down Expand Up @@ -1376,7 +1376,7 @@ func (bc *BlockCache) upload(item *workItem) {
if bc.tmpPath != "" {
localPath := filepath.Join(bc.tmpPath, fileName)

err := os.MkdirAll(filepath.Dir(localPath), 0777)
err := os.MkdirAll(filepath.Dir(localPath), 0755)
if err != nil {
log.Err("BlockCache::upload : error creating directory structure for file %s [%s]", localPath, err.Error())
goto return_safe
Expand Down
24 changes: 11 additions & 13 deletions component/block_cache/block_cache_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"math"
mrand "math/rand/v2"
"os"
Expand Down Expand Up @@ -335,7 +334,7 @@ func (suite *blockCacheTestSuite) TestFileOpenClose() {
storagePath := filepath.Join(tobj.fake_storage_path, fileName)
data := make([]byte, 5*_1MB)
_, _ = rand.Read(data)
ioutil.WriteFile(storagePath, data, 0777)
os.WriteFile(storagePath, data, 0777)

options := internal.OpenFileOptions{Name: fileName}
h, err := tobj.blockCache.OpenFile(options)
Expand Down Expand Up @@ -560,15 +559,16 @@ func (suite *blockCacheTestSuite) TestFileReadBlockCacheTmpPath() {

tmpPath := tobj.blockCache.tmpPath

files, err := ioutil.ReadDir(tmpPath)
files, err := os.ReadDir(tmpPath)
suite.assert.NoError(err)

var size1048576, size7 bool
for _, file := range files {
if file.Size() == 1048576 {
info, _ := file.Info()
if info.Size() == 1048576 {
size1048576 = true
}
if file.Size() == 7 {
if info.Size() == 7 {
size7 = true
}
}
Expand All @@ -592,7 +592,7 @@ func (suite *blockCacheTestSuite) TestFileReadSerial() {
storagePath := filepath.Join(tobj.fake_storage_path, fileName)
data := make([]byte, 50*_1MB)
_, _ = rand.Read(data)
ioutil.WriteFile(storagePath, data, 0777)
os.WriteFile(storagePath, data, 0777)

options := internal.OpenFileOptions{Name: fileName}
h, err := tobj.blockCache.OpenFile(options)
Expand Down Expand Up @@ -634,7 +634,7 @@ func (suite *blockCacheTestSuite) TestFileReadRandom() {
storagePath := filepath.Join(tobj.fake_storage_path, fileName)
data := make([]byte, 100*_1MB)
_, _ = rand.Read(data)
ioutil.WriteFile(storagePath, data, 0777)
os.WriteFile(storagePath, data, 0777)

options := internal.OpenFileOptions{Name: fileName}
h, err := tobj.blockCache.OpenFile(options)
Expand Down Expand Up @@ -675,7 +675,7 @@ func (suite *blockCacheTestSuite) TestFileReadRandomNoPrefetch() {
storagePath := filepath.Join(tobj.fake_storage_path, fileName)
data := make([]byte, 100*_1MB)
_, _ = rand.Read(data)
ioutil.WriteFile(storagePath, data, 0777)
os.WriteFile(storagePath, data, 0777)

options := internal.OpenFileOptions{Name: fileName}
h, err := tobj.blockCache.OpenFile(options)
Expand Down Expand Up @@ -792,7 +792,7 @@ func (suite *blockCacheTestSuite) TestOpenWithTruncate() {
storagePath := filepath.Join(tobj.fake_storage_path, fileName)
data := make([]byte, 5*_1MB)
_, _ = rand.Read(data)
ioutil.WriteFile(storagePath, data, 0777)
os.WriteFile(storagePath, data, 0777)

options := internal.OpenFileOptions{Name: fileName}
h, err := tobj.blockCache.OpenFile(options)
Expand Down Expand Up @@ -885,7 +885,6 @@ func (suite *blockCacheTestSuite) TestWriteFileMultiBlock() {
suite.assert.NotNil(tobj.blockCache)

path := getTestFileName(suite.T().Name())
storagePath := filepath.Join(tobj.fake_storage_path, path)

data := make([]byte, 5*_1MB)
_, _ = rand.Read(data)
Expand All @@ -908,7 +907,7 @@ func (suite *blockCacheTestSuite) TestWriteFileMultiBlock() {
err = tobj.blockCache.CloseFile(internal.CloseFileOptions{Handle: h})
suite.assert.NoError(err)

storagePath = filepath.Join(tobj.fake_storage_path, path)
storagePath := filepath.Join(tobj.fake_storage_path, path)
fs, err := os.Stat(storagePath)
suite.assert.NoError(err)
suite.assert.Equal(fs.Size(), int64(len(data)))
Expand All @@ -924,7 +923,6 @@ func (suite *blockCacheTestSuite) TestWriteFileMultiBlockWithOverwrite() {
suite.assert.NotNil(tobj.blockCache)

path := getTestFileName(suite.T().Name())
storagePath := filepath.Join(tobj.fake_storage_path, path)

data := make([]byte, 5*_1MB)
_, _ = rand.Read(data)
Expand Down Expand Up @@ -959,7 +957,7 @@ func (suite *blockCacheTestSuite) TestWriteFileMultiBlockWithOverwrite() {
err = tobj.blockCache.CloseFile(internal.CloseFileOptions{Handle: h})
suite.assert.NoError(err)

storagePath = filepath.Join(tobj.fake_storage_path, path)
storagePath := filepath.Join(tobj.fake_storage_path, path)
fs, err := os.Stat(storagePath)
suite.assert.NoError(err)
suite.assert.Equal(fs.Size(), int64(len(data)))
Expand Down
2 changes: 1 addition & 1 deletion component/file_cache/file_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ func (suite *fileCacheTestSuite) TestReadFileWithRefresh() {

// Now wait for refresh timeout and we shall get the updated content on next read
byteArr = []byte("test data123456")
err = os.WriteFile(suite.fake_storage_path+"/"+path, []byte("test data123456"), 0777)
err = os.WriteFile(suite.fake_storage_path+"/"+path, byteArr, 0777)
suite.assert.NoError(err)
time.Sleep(2 * time.Second)
f, err = suite.fileCache.OpenFile(options)
Expand Down
8 changes: 4 additions & 4 deletions component/loopback/loopback_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (lfs *LoopbackFS) ReadInBuffer(options internal.ReadInBufferOptions) (int,
f := options.Handle.GetFileObject()

if f == nil {
f1, err := os.OpenFile(filepath.Join(lfs.path, options.Handle.Path), os.O_RDONLY, 0666)
f1, err := os.Open(filepath.Join(lfs.path, options.Handle.Path))
if err != nil {
return 0, nil
}
Expand Down Expand Up @@ -397,15 +397,15 @@ func (lfs *LoopbackFS) Chown(options internal.ChownOptions) error {
func (lfs *LoopbackFS) StageData(options internal.StageDataOptions) error {
log.Trace("LoopbackFS::StageData : name=%s, id=%s", options.Name, options.Id)
path := fmt.Sprintf("%s_%s", filepath.Join(lfs.path, options.Name), strings.ReplaceAll(options.Id, "/", "_"))
return os.WriteFile(path, options.Data, 0777)
return os.WriteFile(path, options.Data, 0644)
}

func (lfs *LoopbackFS) CommitData(options internal.CommitDataOptions) error {
log.Trace("LoopbackFS::StageData : name=%s", options.Name)

mainFilepath := filepath.Join(lfs.path, options.Name)

blob, err := os.OpenFile(mainFilepath, os.O_RDWR|os.O_CREATE, os.FileMode(0777))
blob, err := os.OpenFile(mainFilepath, os.O_RDWR|os.O_CREATE, os.FileMode(0644))
if err != nil {
log.Err("LoopbackFS::CommitData : error opening [%s]", err)
return err
Expand All @@ -415,7 +415,7 @@ func (lfs *LoopbackFS) CommitData(options internal.CommitDataOptions) error {
path := fmt.Sprintf("%s_%s", filepath.Join(lfs.path, options.Name), strings.ReplaceAll(id, "/", "_"))
info, err := os.Lstat(path)
if err == nil {
block, err := os.OpenFile(path, os.O_RDONLY, os.FileMode(0666))
block, err := os.Open(path)
if err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions component/stream/read_write_filename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,7 @@ func (suite *streamTestSuite) TestFilenameStreamOnly() {

// open new file
handle = &handlemap.Handle{Size: int64(4 * MB), Path: fileNames[1]}
getFileBlockOffsetsOptions = internal.GetFileBlockOffsetsOptions{Name: fileNames[0]}
openFileOptions = internal.OpenFileOptions{Name: fileNames[1], Flags: os.O_RDONLY, Mode: os.FileMode(0777)}
bol = &common.BlockOffsetList{
BlockList: []*common.Block{{StartIndex: 0, EndIndex: 2 * MB}, {StartIndex: 2, EndIndex: 4 * MB}},
}

suite.mock.EXPECT().OpenFile(openFileOptions).Return(handle, nil)
_, _ = suite.stream.OpenFile(openFileOptions)
Expand Down
4 changes: 0 additions & 4 deletions component/stream/read_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,7 @@ func (suite *streamTestSuite) TestStreamOnly() {

// create new handle
handle = &handlemap.Handle{Size: int64(4 * MB), Path: fileNames[0]}
getFileBlockOffsetsOptions = internal.GetFileBlockOffsetsOptions{Name: fileNames[0]}
openFileOptions = internal.OpenFileOptions{Name: fileNames[0], Flags: os.O_RDONLY, Mode: os.FileMode(0777)}
bol = &common.BlockOffsetList{
BlockList: []*common.Block{{StartIndex: 0, EndIndex: 2 * MB}, {StartIndex: 2, EndIndex: 4 * MB}},
}

suite.mock.EXPECT().OpenFile(openFileOptions).Return(handle, nil)
_, _ = suite.stream.OpenFile(openFileOptions)
Expand Down
3 changes: 2 additions & 1 deletion internal/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package internal

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -104,7 +105,7 @@ func (s *pipelineTestSuite) TestStartStopCreateNewPipeline() {
p, err := NewPipeline([]string{"ComponentA", "ComponentB"}, false)
s.assert.NoError(err)

err = p.Start(nil)
err = p.Start(context.TODO())
s.assert.NoError(err)

err = p.Stop()
Expand Down
6 changes: 3 additions & 3 deletions internal/stats_manager/stats_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (sc *StatsCollector) statsDumper() {
return
}

f, err := os.OpenFile(common.TransferPipe, os.O_CREATE|os.O_WRONLY, 0777)
f, err := os.OpenFile(common.TransferPipe, os.O_WRONLY, 0)
if err != nil {
log.Err("stats_manager::statsDumper : unable to open pipe file [%v]", err)
disableMonitoring()
Expand Down Expand Up @@ -137,7 +137,7 @@ func statsPolling() {
}

// open polling pipe
pf, err := os.OpenFile(common.PollingPipe, os.O_RDONLY, os.ModeNamedPipe)
pf, err := os.Open(common.PollingPipe)
if err != nil {
fmt.Printf("stats_manager::statsPolling : unable to open pipe file [%v]", err)
return
Expand All @@ -157,7 +157,7 @@ func statsPolling() {
}

// open transfer pipe
tf, err := os.OpenFile(common.TransferPipe, os.O_CREATE|os.O_WRONLY, 0777)
tf, err := os.OpenFile(common.TransferPipe, os.O_WRONLY, 0)
if err != nil {
log.Err("stats_manager::statsPolling : unable to open pipe file [%v]", err)
disableMonitoring()
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark_test/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func createSingleFile(size float32, path string) (float64, error) {
if err != nil {
return 0, err
}
return float64(time.Now().Sub(start)), nil
return float64(time.Since(start)), nil
}

func (suite *benchmarkSuite) TestCreateSingleFiles() {
Expand Down
7 changes: 0 additions & 7 deletions test/e2e_tests/data_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,6 @@ func writeSparseData(suite *dataValidationTestSuite, fh *os.File, offsets []int6
}
}

func min(x, y int) int {
if x < y {
return x
}
return y
}

// Creates the file with filePath and puts random data of size bytes
func generateFileWithRandomData(suite *dataValidationTestSuite, filePath string, size int) {
fh, err := os.Create(filePath)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e_tests/dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (suite *dirTestSuite) TestDirGetStats() {

stat, err := os.Stat(dirName)
suite.NoError(err)
modTineDiff := time.Now().Sub(stat.ModTime())
modTineDiff := time.Since(stat.ModTime())

// for directory block blob may still return timestamp as 0
// So compare the time only if epoch is non-zero
Expand Down
Loading
Loading