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

Test pr 865 #872

Merged
merged 4 commits into from
Aug 2, 2023
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
4 changes: 2 additions & 2 deletions azure_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (util *snowflakeAzureClient) uploadFile(
})
} else {
var f *os.File
f, err = os.OpenFile(dataFile, os.O_RDONLY, os.ModePerm)
f, err = os.Open(dataFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -273,7 +273,7 @@ func (util *snowflakeAzureClient) nativeDownloadFile(
if meta.mockAzureClient != nil {
blobClient = meta.mockAzureClient
}
f, err := os.OpenFile(fullDstFileName, os.O_CREATE|os.O_WRONLY, os.ModePerm)
f, err := os.OpenFile(fullDstFileName, os.O_CREATE|os.O_WRONLY, readWriteFileMode)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,8 @@

To send information from a stream (rather than a file) use code similar to the code below.
(The ReplaceAll() function is needed on Windows to handle backslashes in the path to the file.)

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.20 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.20 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.20 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

package comment is detached; there should be no blank lines between it and the package statement

Check failure on line 891 in doc.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.20 on Windows

package comment is detached; there should be no blank lines between it and the package statement
fileStream, _ := os.OpenFile(fname, os.O_RDONLY, os.ModePerm)
fileStream, _ := os.Open(fname)
defer func() {
if fileStream != nil {
fileStream.Close()
Expand Down
4 changes: 2 additions & 2 deletions encrypt_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func encryptFile(
if err != nil {
return nil, "", err
}
infile, err := os.OpenFile(filename, os.O_CREATE|os.O_RDONLY, os.ModePerm)
infile, err := os.OpenFile(filename, os.O_CREATE|os.O_RDONLY, readWriteFileMode)
if err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func decryptFile(
return "", err
}
defer tmpOutputFile.Close()
infile, err := os.OpenFile(filename, os.O_RDONLY, os.ModePerm)
infile, err := os.Open(filename)
if err != nil {
return "", err
}
Expand Down
14 changes: 7 additions & 7 deletions encrypt_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestEncryptDecryptFile(t *testing.T) {
data := "test data"
inputFile := "test_encrypt_decrypt_file"

fd, err := os.OpenFile(inputFile, os.O_CREATE|os.O_WRONLY, os.ModePerm)
fd, err := os.Create(inputFile)
if err != nil {
t.Error(err)
}
Expand All @@ -54,7 +54,7 @@ func TestEncryptDecryptFile(t *testing.T) {
}
defer os.Remove(decryptedFile)

fd, err = os.OpenFile(decryptedFile, os.O_RDONLY, os.ModePerm)
fd, err = os.Open(decryptedFile)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func encryptDecryptFile(t *testing.T, encMat snowflakeFileEncryption, expected i
defer os.Remove(decryptedFile)

cnt := 0
fd, err := os.OpenFile(decryptedFile, os.O_RDONLY, os.ModePerm)
fd, err := os.Open(decryptedFile)
if err != nil {
t.Error(err)
}
Expand All @@ -168,7 +168,7 @@ func generateKLinesOfNByteRows(numLines int, numBytes int, tmpDir string) (strin
}
}
fname := path.Join(tmpDir, "file"+strconv.FormatInt(int64(numLines*numBytes), 10))
f, err := os.OpenFile(fname, os.O_CREATE|os.O_WRONLY, os.ModePerm)
f, err := os.Create(fname)
if err != nil {
return "", err
}
Expand All @@ -191,7 +191,7 @@ func generateKLinesOfNFiles(k int, n int, compress bool, tmpDir string) (string,
}
for i := 0; i < n; i++ {
fname := path.Join(tmpDir, "file"+strconv.FormatInt(int64(i), 10))
f, err := os.OpenFile(fname, os.O_CREATE|os.O_WRONLY, os.ModePerm)
f, err := os.Create(fname)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -233,12 +233,12 @@ func generateKLinesOfNFiles(k int, n int, compress bool, tmpDir string) (string,
io.ReadAll(gzipErr)
gzipCmd.Wait()
} else {
fOut, err := os.OpenFile(fname+".gz", os.O_CREATE|os.O_WRONLY, os.ModePerm)
fOut, err := os.Create(fname + ".gz")
if err != nil {
return "", err
}
w := gzip.NewWriter(fOut)
fIn, err := os.OpenFile(fname, os.O_RDONLY, os.ModePerm)
fIn, err := os.Open(fname)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion file_transfer_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestUnitDownloadWithInvalidLocalPath(t *testing.T) {
}
defer os.RemoveAll(tmpDir)
testData := filepath.Join(tmpDir, "data.txt")
f, err := os.OpenFile(testData, os.O_CREATE|os.O_RDWR, os.ModePerm)
f, err := os.Create(testData)
if err != nil {
t.Error(err)
}
Expand Down
7 changes: 4 additions & 3 deletions file_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type snowflakeFileUtil struct {
}

const (
fileChunkSize = 16 * 4 * 1024
fileChunkSize = 16 * 4 * 1024
readWriteFileMode os.FileMode = 0666
)

func (util *snowflakeFileUtil) compressFileWithGzipFromStream(srcStream **bytes.Buffer) (*bytes.Buffer, int, error) {
Expand All @@ -39,12 +40,12 @@ func (util *snowflakeFileUtil) compressFileWithGzip(fileName string, tmpDir stri
basename := baseName(fileName)
gzipFileName := filepath.Join(tmpDir, basename+"_c.gz")

fr, err := os.OpenFile(fileName, os.O_RDONLY, os.ModePerm)
fr, err := os.Open(fileName)
if err != nil {
return "", -1, err
}
defer fr.Close()
fw, err := os.OpenFile(gzipFileName, os.O_WRONLY|os.O_CREATE, os.ModePerm)
fw, err := os.OpenFile(gzipFileName, os.O_WRONLY|os.O_CREATE, readWriteFileMode)
if err != nil {
return "", -1, err
}
Expand Down
4 changes: 2 additions & 2 deletions gcs_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (util *snowflakeGcsClient) uploadFile(
uploadSrc = meta.realSrcStream
}
} else {
uploadSrc, err = os.OpenFile(dataFile, os.O_RDONLY, os.ModePerm)
uploadSrc, err = os.Open(dataFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func (util *snowflakeGcsClient) nativeDownloadFile(
return meta.lastError
}

f, err := os.OpenFile(fullDstFileName, os.O_CREATE|os.O_WRONLY, os.ModePerm)
f, err := os.OpenFile(fullDstFileName, os.O_CREATE|os.O_WRONLY, readWriteFileMode)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions local_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (util *localUtil) uploadOneFileWithRetry(meta *fileMetadata) error {
return nil
}
}
output, err := os.OpenFile(filepath.Join(user, meta.dstFileName), os.O_CREATE|os.O_WRONLY, os.ModePerm)
output, err := os.OpenFile(filepath.Join(user, meta.dstFileName), os.O_CREATE|os.O_WRONLY, readWriteFileMode)
if err != nil {
return err
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (util *localUtil) downloadOneFile(meta *fileMetadata) error {
if err != nil {
return err
}
if err = os.WriteFile(fullDstFileName, data, os.ModePerm); err != nil {
if err = os.WriteFile(fullDstFileName, data, readWriteFileMode); err != nil {
return err
}
fi, err := os.Stat(fullDstFileName)
Expand Down
6 changes: 3 additions & 3 deletions local_storage_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestLocalUpload(t *testing.T) {
gzw := gzip.NewWriter(&b)
gzw.Write([]byte(originalContents))
gzw.Close()
if err := os.WriteFile(fname, b.Bytes(), os.ModePerm); err != nil {
if err := os.WriteFile(fname, b.Bytes(), readWriteFileMode); err != nil {
t.Fatal("could not write to gzip file")
}
putDir, err := os.MkdirTemp("", "put")
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestLocalUpload(t *testing.T) {
if uploadMeta.resStatus != skipped {
t.Fatal("overwrite is false. should have skipped")
}
fileStream, _ := os.OpenFile(fname, os.O_RDONLY, os.ModePerm)
fileStream, _ := os.Open(fname)
ctx := WithFileStream(context.Background(), fileStream)
uploadMeta.srcStream = getFileStream(ctx)

Expand Down Expand Up @@ -116,7 +116,7 @@ func TestDownloadLocalFile(t *testing.T) {
gzw := gzip.NewWriter(&b)
gzw.Write([]byte(originalContents))
gzw.Close()
if err := os.WriteFile(fname, b.Bytes(), os.ModePerm); err != nil {
if err := os.WriteFile(fname, b.Bytes(), readWriteFileMode); err != nil {
t.Fatal("could not write to gzip file")
}
putDir, err := os.MkdirTemp("", "put")
Expand Down
2 changes: 1 addition & 1 deletion ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func initOCSPCache() {
ocspResponseCacheLock = &sync.RWMutex{}

logger.Infof("reading OCSP Response cache file. %v\n", cacheFileName)
f, err := os.OpenFile(cacheFileName, os.O_CREATE|os.O_RDONLY, os.ModePerm)
f, err := os.OpenFile(cacheFileName, os.O_CREATE|os.O_RDONLY, readWriteFileMode)
if err != nil {
logger.Debugf("failed to open. Ignored. %v\n", err)
return
Expand Down
2 changes: 1 addition & 1 deletion ocsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func TestInitOCSPCacheFileCreation(t *testing.T) {
defer func() {
src, _ = os.Open(tmpFileName)
defer src.Close()
dst, _ = os.OpenFile(srcFileName, os.O_WRONLY, os.ModePerm)
dst, _ = os.OpenFile(srcFileName, os.O_WRONLY, readWriteFileMode)
defer dst.Close()
// copy temporary file contents back to original file
if _, err = io.Copy(dst, src); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions put_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestPutError(t *testing.T) {
defer os.RemoveAll(tmpDir)
file1 := filepath.Join(tmpDir, "file1")
remoteLocation := filepath.Join(tmpDir, "remote_loc")
f, err := os.OpenFile(file1, os.O_CREATE|os.O_WRONLY, os.ModePerm)
f, err := os.Create(file1)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestPutWithAutoCompressFalse(t *testing.T) {
}
defer os.RemoveAll(tmpDir)
testData := filepath.Join(tmpDir, "data.txt")
f, err := os.OpenFile(testData, os.O_CREATE|os.O_WRONLY, os.ModePerm)
f, err := os.Create(testData)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestPutOverwrite(t *testing.T) {
}
defer os.RemoveAll(tmpDir)
testData := filepath.Join(tmpDir, "data.txt")
f, err := os.OpenFile(testData, os.O_CREATE|os.O_RDWR, os.ModePerm)
f, err := os.Create(testData)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -392,14 +392,14 @@ func testPutGet(t *testing.T, isStream bool) {
gzw := gzip.NewWriter(&b)
gzw.Write([]byte(originalContents))
gzw.Close()
if err = os.WriteFile(fname, b.Bytes(), os.ModePerm); err != nil {
if err = os.WriteFile(fname, b.Bytes(), readWriteFileMode); err != nil {
t.Fatal("could not write to gzip file")
}

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("create or replace table " + tableName +
" (a int, b string)")
fileStream, err := os.OpenFile(fname, os.O_RDONLY, os.ModePerm)
fileStream, err := os.Open(fname)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -517,15 +517,15 @@ func TestPutGetGcsDownscopedCredential(t *testing.T) {
gzw := gzip.NewWriter(&b)
gzw.Write([]byte(originalContents))
gzw.Close()
if err = os.WriteFile(fname, b.Bytes(), os.ModePerm); err != nil {
if err = os.WriteFile(fname, b.Bytes(), readWriteFileMode); err != nil {
t.Fatal("could not write to gzip file")
}

dsn = dsn + "&GCS_USE_DOWNSCOPED_CREDENTIAL=true"
runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("create or replace table " + tableName +
" (a int, b string)")
fileStream, err := os.OpenFile(fname, os.O_RDONLY, os.ModePerm)
fileStream, err := os.Open(fname)
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion put_get_user_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func putGetUserStage(t *testing.T, tmpDir string, numberOfFiles int, numberOfLin
dbt.mustExec("rm @" + stageName)
var fs *os.File
if isStream {
fs, _ = os.OpenFile(files, os.O_RDONLY, os.ModePerm)
fs, _ = os.Open(files)
dbt.mustExecContext(WithFileStream(context.Background(), fs),
fmt.Sprintf("put 'file://%v' @%v", strings.ReplaceAll(
files, "\\", "\\\\"), stageName))
Expand Down
6 changes: 3 additions & 3 deletions put_get_with_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestPutWithInvalidToken(t *testing.T) {
gzw := gzip.NewWriter(&b)
gzw.Write([]byte(originalContents))
gzw.Close()
if err := os.WriteFile(fname, b.Bytes(), os.ModePerm); err != nil {
if err := os.WriteFile(fname, b.Bytes(), readWriteFileMode); err != nil {
t.Fatal("could not write to gzip file")
}

Expand Down Expand Up @@ -214,7 +214,7 @@ func TestPretendToPutButList(t *testing.T) {
gzw := gzip.NewWriter(&b)
gzw.Write([]byte(originalContents))
gzw.Close()
if err := os.WriteFile(fname, b.Bytes(), os.ModePerm); err != nil {
if err := os.WriteFile(fname, b.Bytes(), readWriteFileMode); err != nil {
t.Fatal("could not write to gzip file")
}

Expand Down Expand Up @@ -283,7 +283,7 @@ func TestPutGetAWSStage(t *testing.T) {
gzw := gzip.NewWriter(&b)
gzw.Write([]byte(originalContents))
gzw.Close()
if err = os.WriteFile(fname, b.Bytes(), os.ModePerm); err != nil {
if err = os.WriteFile(fname, b.Bytes(), readWriteFileMode); err != nil {
t.Fatal("could not write to gzip file")
}

Expand Down
2 changes: 1 addition & 1 deletion s3_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (util *snowflakeS3Client) nativeDownloadFile(
}
}

f, err := os.OpenFile(fullDstFileName, os.O_CREATE|os.O_WRONLY, os.ModePerm)
f, err := os.OpenFile(fullDstFileName, os.O_CREATE|os.O_WRONLY, readWriteFileMode)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion secure_storage_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestCreateCredentialCache(t *testing.T) {
// cleanup
src, _ = os.Open(tmpFileName)
defer src.Close()
dst, _ = os.OpenFile(srcFileName, os.O_WRONLY, os.ModePerm)
dst, _ = os.OpenFile(srcFileName, os.O_WRONLY, readWriteFileMode)
defer dst.Close()
// copy temporary file contents back to original file
if _, err = io.Copy(dst, src); err != nil {
Expand Down
Loading