Skip to content

Commit 6e539e0

Browse files
Refactor fix os exec (#3)
* refactor-fix-os-exec: The os exec command adjusted for mkdir thingy * refactor-fix-os-exec: The os level exit code added
1 parent 90a295d commit 6e539e0

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,25 @@ func HandleRootFS() {
3434
result, err := parserClient.ParseYamlFile(configFile)
3535
if err != nil {
3636
log.Err(err).Msg("Error while running parserCli.ParseYamlFile()")
37+
os.Exit(1)
3738
}
3839

3940
err = rootFsClient.CreateFileDD(rootFsSize, rootFsName)
4041
if err != nil {
4142
log.Err(err).Msg("Error while running rootFsClient.CreateFileDD()")
43+
os.Exit(1)
4244
}
4345

4446
fsErr := rootFsClient.FormatandMountFileSystem(rootFsName, result.TargetDirectory)
4547
if fsErr != nil {
4648
log.Err(fsErr).Msg("Error while running rootFsClient.FormatFileSystem()")
49+
os.Exit(1)
4750
}
4851

4952
err = buildCLient.BuildExportDockerImage(result.Context, result.DockerfilePath, result.TargetDirectory)
5053
if err != nil {
5154
log.Err(err).Msg("Error while running buildCLient.BuildExportDockerImage()")
55+
os.Exit(1)
5256
}
5357

5458
}

src/rootfs.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,31 @@ type RootFSHandler struct{}
1616

1717
func (rootfs *RootFSHandler) FormatandMountFileSystem(path, targetDirectory string) error {
1818

19-
cmd := exec.Command("mkdir", "-p", targetDirectory)
20-
output, err := cmd.CombinedOutput()
19+
err := os.Mkdir(targetDirectory, os.ModeDir)
2120
if err != nil {
22-
log.Err(err).Msg("Error while running mkdir")
23-
log.Info().Msgf("Mkdir exec output: %s", string(output))
21+
log.Err(err).Msg("Error while calling os.Mkdir")
2422
return err
2523
}
2624

27-
cmd = exec.Command("mkfs.ext4", path)
28-
output, err = cmd.CombinedOutput()
25+
cmd := exec.Command("mkfs.ext4", path)
26+
output, err := cmd.CombinedOutput()
2927
if err != nil {
3028
log.Err(err).Msg("Error running mkfs.ext4:")
3129
log.Info().Msgf("Output: %s", string(output))
3230
return err
3331
}
3432

35-
log.Info().Msgf("Output: %s", string(output))
33+
log.Info().Msgf("Output of mkfs.ext4 : %s", string(output))
3634

3735
cmd = exec.Command("mount", path, targetDirectory)
3836
output, err = cmd.CombinedOutput()
3937
if err != nil {
40-
log.Err(err).Msg("Error running mount")
41-
log.Info().Msgf("Mount exec output: %s", string(output))
38+
log.Err(err).Msg("Error running mount command")
39+
log.Info().Msgf("Mount errored status: %s", string(output))
4240
return err
4341
}
4442

45-
log.Info().Msgf("Mount exec output: %s", string(output))
43+
log.Info().Msgf("Mount status: %s", string(output))
4644
return nil
4745
}
4846

0 commit comments

Comments
 (0)