Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Commit

Permalink
create lib folder in DockerCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
jason committed Jan 19, 2020
1 parent 141cd65 commit 2e40d9d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020011619
2020011922
78 changes: 78 additions & 0 deletions container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var (
LD_LIBRARY_PATH_DEFAULT = []string{"lib", "lib64", "lib/x86_64-linux-gnu", "usr/lib/x86_64-linux-gnu", "usr/lib", "usr/local/lib", "usr/lib64", "usr/local/lib64"}
CACHE_FOLDER = []string{"/var/cache/apt/archives"}
UNSTALL_FOLDER = []string{".lpmxsys", "sync", "bin", ".docker", "package"}
//files copy excluded for patch folder in newly created container
EXCLUDE_FILES = []string{"ld.so"}
)

//located inside $/.lpmxsys/.info
Expand Down Expand Up @@ -2130,6 +2132,13 @@ func DockerCreate(name string, container_name string, volume_map string) *Error
configmap["elf_loader"] = ld_new_path
}

//20200117 we changed the way of loading patched ld.so and other dependencies, we directly make a directory in rw folder named lib, and put the other dependencies in it
new_lib_path := fmt.Sprintf("%s/rw/lib", rootfolder)
cerr := walkfsandcopy(fmt.Sprintf("%s/patch", filepath.Dir(filepath.Dir(rootfolder))), new_lib_path, EXCLUDE_FILES)
if cerr != nil {
return cerr
}

//add current user to /etc/passwd user gid to /etc/group
user, err := user.Current()
if err != nil {
Expand Down Expand Up @@ -3123,6 +3132,75 @@ func walkContainerRoot(con *Container) ([]string, []string, *Error) {
return bineries, libs, nil
}

func walkfsandcopy(src, dest string, excludes []string) *Error {
if !FolderExist(src) {
cerr := ErrNew(ErrNExist, fmt.Sprintf("source folder: %s does not exist", src))
return cerr
}

if !FolderExist(dest) {
err := os.MkdirAll(dest, os.FileMode(FOLDER_MODE))
if err != nil {
cerr := ErrNew(err, fmt.Sprintf("could not create dest dir: %s", dest))
return cerr
}
}

err := filepath.Walk(src, func(path string, f os.FileInfo, err error) error {
if err != nil {
return err
}
if f.IsDir() && f.Name() == ".lpmx" {
return filepath.SkipDir
}
file_type, ferr := FileType(path)
if ferr != nil {
return ferr.Err
}

filename := filepath.Base(path)
bskip := false
for _, exclude := range excludes {
if filename == exclude {
bskip = true
break
}
}

if !bskip {
dest_file := fmt.Sprintf("%s/%s", dest, filename)
//if normal regular file, directly copy it to target folder
if file_type == TYPE_REGULAR {
_, cerr := CopyFile(path, dest_file)
if cerr != nil {
return cerr.Err
}
}
//if normal symlink file, create symlink file
if file_type == TYPE_SYMLINK {
link, lerr := os.Readlink(path)
if lerr != nil {
cerr := ErrNew(lerr, fmt.Sprintf("could not successfully resolve symlink: %s", path))
return cerr.Err
}
oerr := os.Symlink(link, dest_file)
if oerr != nil {
cerr := ErrNew(oerr, fmt.Sprintf("could not create symlink %s -> %s", dest_file, link))
return cerr.Err
}
}
}

return nil
})

if err != nil {
cerr := ErrNew(err, fmt.Sprintf("filepath walk: %s encounters error", src))
return cerr
}
return nil
}

func walkSpecificDir(dir string) ([]string, *Error) {
return walkfs(dir)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
)

const (
VERSION = "alpha-1.2"
VERSION = "alpha-1.3"
)

func checkCompleteness() *Error {
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func GetFileLength(file string) (int64, *Error) {
}

func FileType(file string) (int8, *Error) {
fi, err := os.Stat(file)
fi, err := os.Lstat(file)
if err != nil {
cerr := ErrNew(ErrFileStat, fmt.Sprintf("os.stat %s error: %s", file, err.Error()))
return -1, cerr
Expand Down

0 comments on commit 2e40d9d

Please sign in to comment.