@@ -20,6 +20,7 @@ import (
20
20
"net"
21
21
"os"
22
22
"os/exec"
23
+ "path/filepath"
23
24
"strconv"
24
25
"strings"
25
26
"sync"
@@ -70,6 +71,9 @@ const (
70
71
FINDMNT_COMMAND = "findmnt"
71
72
CAT_COMMAND = "cat"
72
73
RPM_COMMAND = "rpm-host"
74
+
75
+ // For Raw Block Volumes, the name of the bind-mounted file inside StagingTargetPath
76
+ RawBlockStagingFile = "mountfile"
73
77
)
74
78
75
79
// Util interface
@@ -450,3 +454,36 @@ func ValidateFssId(id string) *FSSVolumeHandler {
450
454
}
451
455
return volumeHandler
452
456
}
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