Skip to content

Commit

Permalink
refactor: cleanup unused CopyHostDirectoryContent
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
(cherry picked from commit f3a3fb3)
  • Loading branch information
c3y1huang authored and David Ko committed Aug 21, 2023
1 parent 3dd7ca3 commit 23eab07
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,44 +564,6 @@ func RemoveHostDirectoryContent(directory string) (err error) {
return nil
}

func CopyHostDirectoryContent(src, dest string) (err error) {
defer func() {
err = errors.Wrapf(err, "failed to copy the content from %v to %v for the host", src, dest)
}()

srcDir, err := filepath.Abs(filepath.Clean(src))
if err != nil {
return err
}
destDir, err := filepath.Abs(filepath.Clean(dest))
if err != nil {
return err
}
if strings.Count(srcDir, "/") < 2 || strings.Count(destDir, "/") < 2 {
return fmt.Errorf("prohibit copying the content for the top level of directory %v or %v", srcDir, destDir)
}

initiatorNSPath := iscsiutil.GetHostNamespacePath(HostProcPath)
nsExec, err := iscsiutil.NewNamespaceExecutor(initiatorNSPath)
if err != nil {
return err
}

// There can be no src directory, hence returning nil is fine.
if _, err := nsExec.Execute("bash", []string{"-c", fmt.Sprintf("ls %s", filepath.Join(srcDir, "*"))}); err != nil {
return nil
}
// Check if the dest directory exists.
if _, err := nsExec.Execute("mkdir", []string{"-p", destDir}); err != nil {
return err
}
// The flag `-n` means not overwriting an existing file.
if _, err := nsExec.Execute("bash", []string{"-c", fmt.Sprintf("cp -an %s %s", filepath.Join(srcDir, "*"), destDir)}); err != nil {
return err
}
return nil
}

type filteredLoggingHandler struct {
filteredPaths map[string]struct{}
handler http.Handler
Expand Down

0 comments on commit 23eab07

Please sign in to comment.