Skip to content

Commit

Permalink
Removed dead code issue #256
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Dec 6, 2020
1 parent b7d4ae2 commit 875decb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
20 changes: 0 additions & 20 deletions util/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package util

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
Expand All @@ -39,25 +38,6 @@ func ChmodR(path string, filePerm, dirPerm os.FileMode) error {
})
}

// CopyFileContents - Copy/overwrite src to dst
func CopyFileContents(src string, dst string) error {
// Calling f.Sync() should be necessary as long as the
// returned err is properly checked. The only reason
// this would fail implicitly (meaning the file isn't
// available to a Stat() called immediately after calling
// this function) would be because the kernel or filesystem
// is inherently broken.
contents, err := ioutil.ReadFile(filepath.Clean(src))
if err != nil {
return err
}
stat, err := os.Stat(src)
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Clean(dst), contents, stat.Mode())
}

// ByteCountBinary - Pretty print byte size
func ByteCountBinary(b int64) string {
const unit = 1024
Expand Down
41 changes: 0 additions & 41 deletions util/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,11 @@ package util
*/

import (
"bytes"
"crypto/rand"
"fmt"
"io/ioutil"
"os"
"testing"
)

func randomData() []byte {
buf := make([]byte, 128)
rand.Read(buf)
return buf
}

func TestCopyFileContents(t *testing.T) {
sample := randomData()
tmpfile, err := ioutil.TempFile("", "sliver-unit-test")
if err != nil {
t.Error(err)
}
defer os.Remove(tmpfile.Name()) // clean up
if _, err := tmpfile.Write(sample); err != nil {
t.Error(err)
}
err = tmpfile.Close()
if err != nil {
t.Error(err)
}

dst := fmt.Sprintf("%s.2", tmpfile.Name())
CopyFileContents(tmpfile.Name(), dst)

srcData, err := ioutil.ReadFile(tmpfile.Name())
if err != nil {
t.Error(err)
}
dstData, err := ioutil.ReadFile(dst)
if err != nil {
t.Error(err)
}

if !bytes.Equal(sample, srcData) {
t.Error(fmt.Errorf("Sample and src do not match:\nsample: %v\n src: %v", sample, srcData))
}
if !bytes.Equal(dstData, srcData) {
t.Error(fmt.Errorf("dst and src do not match:\ndst: %v\nsrc: %v", dstData, srcData))
}

}

0 comments on commit 875decb

Please sign in to comment.