mirror of https://github.com/portainer/portainer
fix(api): ignore directory existence check and use os.MkdirAll (#1719)
parent
706490db5e
commit
9e47aedbe6
|
@ -42,20 +42,17 @@ func NewService(dataStorePath, fileStorePath string) (*Service, error) {
|
||||||
fileStorePath: path.Join(dataStorePath, fileStorePath),
|
fileStorePath: path.Join(dataStorePath, fileStorePath),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking if a mount directory exists is broken with Go on Windows.
|
err := os.MkdirAll(dataStorePath, 0755)
|
||||||
// This will need to be reviewed after the issue has been fixed in Go.
|
|
||||||
// See: https://github.com/portainer/portainer/issues/474
|
|
||||||
// err := createDirectoryIfNotExist(dataStorePath, 0755)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
|
|
||||||
err := service.createDirectoryInStoreIfNotExist(TLSStorePath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = service.createDirectoryInStoreIfNotExist(ComposeStorePath)
|
err = service.createDirectoryInStore(TLSStorePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = service.createDirectoryInStore(ComposeStorePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -78,7 +75,7 @@ func (service *Service) GetStackProjectPath(stackIdentifier string) string {
|
||||||
// It returns the path to the folder where the file is stored.
|
// It returns the path to the folder where the file is stored.
|
||||||
func (service *Service) StoreStackFileFromString(stackIdentifier, fileName, stackFileContent string) (string, error) {
|
func (service *Service) StoreStackFileFromString(stackIdentifier, fileName, stackFileContent string) (string, error) {
|
||||||
stackStorePath := path.Join(ComposeStorePath, stackIdentifier)
|
stackStorePath := path.Join(ComposeStorePath, stackIdentifier)
|
||||||
err := service.createDirectoryInStoreIfNotExist(stackStorePath)
|
err := service.createDirectoryInStore(stackStorePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -99,7 +96,7 @@ func (service *Service) StoreStackFileFromString(stackIdentifier, fileName, stac
|
||||||
// It returns the path to the folder where the file is stored.
|
// It returns the path to the folder where the file is stored.
|
||||||
func (service *Service) StoreStackFileFromReader(stackIdentifier, fileName string, r io.Reader) (string, error) {
|
func (service *Service) StoreStackFileFromReader(stackIdentifier, fileName string, r io.Reader) (string, error) {
|
||||||
stackStorePath := path.Join(ComposeStorePath, stackIdentifier)
|
stackStorePath := path.Join(ComposeStorePath, stackIdentifier)
|
||||||
err := service.createDirectoryInStoreIfNotExist(stackStorePath)
|
err := service.createDirectoryInStore(stackStorePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -117,7 +114,7 @@ func (service *Service) StoreStackFileFromReader(stackIdentifier, fileName strin
|
||||||
// StoreTLSFile creates a folder in the TLSStorePath and stores a new file with the content from r.
|
// StoreTLSFile creates a folder in the TLSStorePath and stores a new file with the content from r.
|
||||||
func (service *Service) StoreTLSFile(folder string, fileType portainer.TLSFileType, r io.Reader) error {
|
func (service *Service) StoreTLSFile(folder string, fileType portainer.TLSFileType, r io.Reader) error {
|
||||||
storePath := path.Join(TLSStorePath, folder)
|
storePath := path.Join(TLSStorePath, folder)
|
||||||
err := service.createDirectoryInStoreIfNotExist(storePath)
|
err := service.createDirectoryInStore(storePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -201,24 +198,10 @@ func (service *Service) GetFileContent(filePath string) (string, error) {
|
||||||
return string(content), nil
|
return string(content), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// createDirectoryInStoreIfNotExist creates a new directory in the file store if it doesn't exists on the file system.
|
// createDirectoryInStore creates a new directory in the file store
|
||||||
func (service *Service) createDirectoryInStoreIfNotExist(name string) error {
|
func (service *Service) createDirectoryInStore(name string) error {
|
||||||
path := path.Join(service.fileStorePath, name)
|
path := path.Join(service.fileStorePath, name)
|
||||||
return createDirectoryIfNotExist(path, 0700)
|
return os.MkdirAll(path, 0700)
|
||||||
}
|
|
||||||
|
|
||||||
// createDirectoryIfNotExist creates a directory if it doesn't exists on the file system.
|
|
||||||
func createDirectoryIfNotExist(path string, mode uint32) error {
|
|
||||||
_, err := os.Stat(path)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
err = os.Mkdir(path, os.FileMode(mode))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// createFile creates a new file in the file store with the content from r.
|
// createFile creates a new file in the file store with the content from r.
|
||||||
|
|
Loading…
Reference in New Issue