server: ensure /var/lib/ocid/images exists

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-08-04 16:34:30 +02:00 committed by Mrunal Patel
parent fc3b7b5aae
commit c5d0f23e5a
2 changed files with 10 additions and 3 deletions

View file

@ -3,6 +3,7 @@ package server
import (
"errors"
"os"
"path/filepath"
"github.com/containers/image/directory"
"github.com/containers/image/image"
@ -52,11 +53,11 @@ func (s *Server) PullImage(ctx context.Context, req *pb.PullImageRequest) (*pb.P
if err != nil {
return nil, err
}
// TODO: make sure this dir exists?
if err := os.Mkdir("/var/lib/ocid/images/"+tr.StringWithinTransport(), 0755); err != nil {
if err := os.Mkdir(filepath.Join(imageStore, tr.StringWithinTransport()), 0755); err != nil {
return nil, err
}
dir, err := directory.NewReference("/var/lib/ocid/images/" + tr.StringWithinTransport())
dir, err := directory.NewReference(filepath.Join(imageStore, tr.StringWithinTransport()))
if err != nil {
return nil, err
}

View file

@ -2,6 +2,7 @@ package server
import (
"fmt"
"os"
"github.com/mrunalp/ocid/oci"
"github.com/mrunalp/ocid/utils"
@ -9,6 +10,7 @@ import (
const (
runtimeAPIVersion = "v1alpha1"
imageStore = "/var/lib/ocid/images"
)
// Server implements the RuntimeService and ImageService
@ -26,6 +28,10 @@ func New(runtimePath, sandboxDir, containerDir string) (*Server, error) {
return nil, fmt.Errorf("failed to set server as subreaper: %v", err)
}
if err := os.MkdirAll(imageStore, 0755); err != nil {
return nil, err
}
r, err := oci.New(runtimePath, containerDir)
if err != nil {
return nil, err