@@ -21,33 +21,53 @@ import (
2121 "io/ioutil"
2222 "net"
2323 "os"
24+ "path"
2425 "path/filepath"
2526 "strings"
2627)
2728
28- func Compose (r * util.Repo , loaderImage string , imageSize int64 , uploadPath string , appName string , commandLine string , verbose bool ) error {
29- zfsBuilderPath , err := r .GetZfsBuilderImagePath ()
30- if err != nil {
31- return err
32- }
33- // Initialize an empty image based on the provided loader image. imageSize is used to
34- // determine the size of the user partition.
35- err = r .InitializeZfsImage (loaderImage , appName , imageSize )
29+ func Compose (r * util.Repo , loaderImage string , imageSize int64 , filesystem string , uploadPath string , appName string , commandLine string , verbose bool ) error {
30+ // If all is well, we have to start preparing the files for upload.
31+ paths , err := CollectPathContents (uploadPath )
3632 if err != nil {
3733 return err
3834 }
3935
4036 // Get the path of imported image.
4137 imagePath := r .ImagePath ("qemu" , appName )
4238
43- paths , err := CollectPathContents (uploadPath )
44- if err != nil {
45- return err
46- }
39+ if filesystem == "zfs" {
40+ // Create ZFS
41+ zfsBuilderPath , err := r .GetZfsBuilderImagePath ()
42+ if err != nil {
43+ return err
44+ }
45+ // Initialize an empty image based on the provided loader image. imageSize is used to
46+ // determine the size of the user partition.
47+ err = r .InitializeZfsImage (loaderImage , appName , imageSize )
48+ if err != nil {
49+ return err
50+ }
4751
48- // Upload the specified path onto virtual image.
49- if _ , err = UploadPackageContents (r , imagePath , paths , nil , verbose , zfsBuilderPath ); err != nil {
50- return err
52+ // Upload the specified path onto virtual image.
53+ if _ , err = UploadPackageContents (r , imagePath , paths , nil , verbose , zfsBuilderPath ); err != nil {
54+ return err
55+ }
56+ } else {
57+ // Create ROFS
58+ // Create temporary folder in which the image will be composed.
59+ tmp , _ := ioutil .TempDir ("" , "capstan" )
60+ // Once this function is finished, remove temporary file.
61+ defer os .RemoveAll (tmp )
62+ rofs_image_path := path .Join (tmp , "rofs.img" )
63+
64+ if err := util .WriteRofsImage (rofs_image_path , paths , uploadPath , verbose ); err != nil {
65+ return fmt .Errorf ("Failed to write ROFS image named %s.\n Error was: %s" , rofs_image_path , err )
66+ }
67+
68+ if err = r .CreateRofsImage (loaderImage , appName , rofs_image_path ); err != nil {
69+ return fmt .Errorf ("Failed to create ROFS image named %s.\n Error was: %s" , appName , err )
70+ }
5171 }
5272
5373 if commandLine != "" {
0 commit comments