本文整理匯總了Golang中github.com/lxc/lxd/shared.ParseLXDFileHeaders函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseLXDFileHeaders函數的具體用法?Golang ParseLXDFileHeaders怎麽用?Golang ParseLXDFileHeaders使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ParseLXDFileHeaders函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: containerFilePut
func containerFilePut(c container, path string, r *http.Request) Response {
// Extract file ownership and mode from headers
uid, gid, mode := shared.ParseLXDFileHeaders(r.Header)
// Write file content to a tempfile
temp, err := ioutil.TempFile("", "lxd_forkputfile_")
if err != nil {
return InternalError(err)
}
defer func() {
temp.Close()
os.Remove(temp.Name())
}()
_, err = io.Copy(temp, r.Body)
if err != nil {
return InternalError(err)
}
// Transfer the file into the container
err = c.FilePush(temp.Name(), path, uid, gid, mode)
if err != nil {
return InternalError(err)
}
return EmptySyncResponse
}
示例2: PullFile
func (c *Client) PullFile(container string, p string) (int, int, os.FileMode, io.ReadCloser, error) {
uri := c.url(shared.APIVersion, "containers", container, "files")
query := url.Values{"path": []string{p}}
r, err := c.getRaw(uri + "?" + query.Encode())
if err != nil {
return 0, 0, 0, nil, err
}
uid, gid, mode := shared.ParseLXDFileHeaders(r.Header)
return uid, gid, mode, r.Body, nil
}
示例3: containerFilePut
func containerFilePut(pid int, r *http.Request, p string, idmapset *shared.IdmapSet) Response {
uid, gid, mode, err := shared.ParseLXDFileHeaders(r.Header)
if err != nil {
return BadRequest(err)
}
uid, gid = idmapset.ShiftIntoNs(uid, gid)
if uid == -1 || gid == -1 {
return BadRequest(fmt.Errorf("unmapped uid or gid specified"))
}
temp, err := ioutil.TempFile("", "lxd_forkputfile_")
if err != nil {
return InternalError(err)
}
defer func() {
temp.Close()
os.Remove(temp.Name())
}()
_, err = io.Copy(temp, r.Body)
if err != nil {
return InternalError(err)
}
cmd := exec.Command(
os.Args[0],
"forkputfile",
temp.Name(),
fmt.Sprintf("%d", pid),
p,
fmt.Sprintf("%d", uid),
fmt.Sprintf("%d", gid),
fmt.Sprintf("%d", mode&os.ModePerm),
)
out, err := cmd.CombinedOutput()
if err != nil {
return InternalError(fmt.Errorf("%s: %s", err.Error(), string(out)))
}
return EmptySyncResponse
}
示例4: containerFilePut
func containerFilePut(d *Daemon, pid int, r *http.Request, p string, idmapset *shared.IdmapSet) Response {
uid, gid, mode := shared.ParseLXDFileHeaders(r.Header)
if idmapset != nil {
uid, gid = idmapset.ShiftIntoNs(uid, gid)
}
temp, err := ioutil.TempFile("", "lxd_forkputfile_")
if err != nil {
return InternalError(err)
}
defer func() {
temp.Close()
os.Remove(temp.Name())
}()
_, err = io.Copy(temp, r.Body)
if err != nil {
return InternalError(err)
}
cmd := exec.Command(
d.execPath,
"forkputfile",
temp.Name(),
fmt.Sprintf("%d", pid),
p,
fmt.Sprintf("%d", uid),
fmt.Sprintf("%d", gid),
fmt.Sprintf("%d", mode&os.ModePerm),
)
out, err := cmd.CombinedOutput()
if err != nil {
return InternalError(fmt.Errorf(strings.TrimRight(string(out), "\n")))
}
return EmptySyncResponse
}