@@ -20,6 +20,7 @@ import (
2020 "net"
2121 "os"
2222 "os/exec"
23+ "path/filepath"
2324 "strconv"
2425 "strings"
2526 "sync"
@@ -70,6 +71,9 @@ const (
7071 FINDMNT_COMMAND = "findmnt"
7172 CAT_COMMAND = "cat"
7273 RPM_COMMAND = "rpm-host"
74+
75+ // For Raw Block Volumes, the name of the bind-mounted file inside StagingTargetPath
76+ RawBlockStagingFile = "mountfile"
7377)
7478
7579// Util interface
@@ -450,3 +454,36 @@ func ValidateFssId(id string) *FSSVolumeHandler {
450454 }
451455 return volumeHandler
452456}
457+
458+ func GetStagingTargetPathForFile (stagingTargetPath string ) string {
459+ stagingTargetPathFile := filepath .Join (stagingTargetPath , RawBlockStagingFile )
460+ return stagingTargetPathFile
461+ }
462+
463+ // Creates a file on the specified path after creating the containing directory
464+ func CreateFilePath (logger * zap.SugaredLogger , path string ) error {
465+ pathDir := filepath .Dir (path )
466+
467+ logger .Infof ("trying to create surrounding directory %s" , pathDir )
468+ err := os .MkdirAll (pathDir , 0750 )
469+ if err != nil {
470+ logger .Infof ("failed to create surrounding directory %s" , pathDir )
471+ return err
472+ }
473+
474+ logger .Infof ("created surrounding directory, trying to create the target file %s" , path )
475+ file , fileErr := os .OpenFile (path , os .O_CREATE , 0640 )
476+ if fileErr != nil && ! os .IsExist (fileErr ) {
477+ logger .Infof ("failed to create/open the target file at %s" , path )
478+ return fileErr
479+ }
480+
481+ fileErr = file .Close ()
482+ if fileErr != nil {
483+ logger .Infof ("failed to close %s" , path )
484+ return fileErr
485+ }
486+
487+ logger .Infof ("ensured file at %s" , path )
488+ return nil
489+ }
0 commit comments