Handle device symlink.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2017-08-07 22:25:26 +00:00
parent be54e9a6c0
commit 4c5cea9258
2 changed files with 23 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
"strings"
@@ -402,3 +403,16 @@ func (c *criContainerdService) ensureImageExists(ctx context.Context, ref string
}
return &newImage, nil
}
// resolveSymbolicLink resolves a possbile symlink path. If the path is a symlink, returns resolved
// path; if not, returns the original path.
func resolveSymbolicLink(path string) (string, error) {
info, err := os.Lstat(path)
if err != nil {
return "", err
}
if info.Mode()&os.ModeSymlink != os.ModeSymlink {
return path, nil
}
return filepath.EvalSymlinks(path)
}