Skip to content

[BUG] WARN Failed to check if the directory is empty: open data: no such file or directory #1977

@mcarbonneaux

Description

@mcarbonneaux

Expected Behavior

no warning !
and normaly the massage must be ERR and not WARN!

Actual Behavior

when start convertion : WARN Failed to check if the directory is empty: open data: no such file or directory
the directory is not empty, it's containt only one sub directory.

Steps To Reproduce

  myservice:
    image: myimage/myimage
    restart: always
    ports:
      - 5333/tcp
    volumes:
      - /data/mydir:/opt/mydir
WARN Failed to check if the directory is empty: open data: no such file or directory
WARN Skip file in path /data/mydir

the /data/mydir is directory, and contain only one subdir... and /data is directory... and the sub directory containe multiple file...

Kompose Version

v1.33.0 and higher
it's work fine in v1.32.0

Docker-Compose file

myservice:
    image: myimage/myimage
    restart: always
    ports:
      - 5333/tcp
    volumes:
      - /data/mydir:/opt/mydir

Anything else?

i think the problem is in the function checkIsEmptyDir.
they try to recurse the filePath... they found in first a directory data...
but when call recursively checkIsEmptyDir the use relative name data, not the absolute name /data/mydir/data...
they break on first os.ReadDir... but is normal because they try to check data in place of /data/mydir/data.

// checkIsEmptyDir checks if filepath is empty
func checkIsEmptyDir(filePath string) (bool, error) {
files, err := os.ReadDir(filePath)
if err != nil {
return false, err
}
if len(files) == 0 {
return true, err
}
for _, file := range files {
if !file.IsDir() {
return false, nil
}
_, err := checkIsEmptyDir(file.Name())
if err != nil {
return false, err
}
}
return true, nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions