CreateInstanceFile tells Incus to create a file in the instance.
(instanceName string, filePath string, args InstanceFileArgs)
| 1534 | |
| 1535 | // CreateInstanceFile tells Incus to create a file in the instance. |
| 1536 | func (r *ProtocolIncus) CreateInstanceFile(instanceName string, filePath string, args InstanceFileArgs) error { |
| 1537 | if args.Type == "directory" { |
| 1538 | if !r.HasExtension("directory_manipulation") { |
| 1539 | return errors.New("The server is missing the required \"directory_manipulation\" API extension") |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | if args.Type == "symlink" { |
| 1544 | if !r.HasExtension("file_symlinks") { |
| 1545 | return errors.New("The server is missing the required \"file_symlinks\" API extension") |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | if args.WriteMode == "append" { |
| 1550 | if !r.HasExtension("file_append") { |
| 1551 | return errors.New("The server is missing the required \"file_append\" API extension") |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | var requestURL string |
| 1556 | |
| 1557 | if r.IsAgent() { |
| 1558 | requestURL = fmt.Sprintf("%s/1.0/files?path=%s", r.httpBaseURL.String(), url.QueryEscape(filePath)) |
| 1559 | } else { |
| 1560 | path, _, err := r.instanceTypeToPath(api.InstanceTypeAny) |
| 1561 | if err != nil { |
| 1562 | return err |
| 1563 | } |
| 1564 | |
| 1565 | // Prepare the HTTP request |
| 1566 | requestURL = fmt.Sprintf("%s/1.0%s/%s/files?path=%s", r.httpBaseURL.String(), path, url.PathEscape(instanceName), url.QueryEscape(filePath)) |
| 1567 | } |
| 1568 | |
| 1569 | requestURL, err := r.setQueryAttributes(requestURL) |
| 1570 | if err != nil { |
| 1571 | return err |
| 1572 | } |
| 1573 | |
| 1574 | req, err := http.NewRequest("POST", requestURL, args.Content) |
| 1575 | if err != nil { |
| 1576 | return err |
| 1577 | } |
| 1578 | |
| 1579 | req.GetBody = func() (io.ReadCloser, error) { |
| 1580 | _, err := args.Content.Seek(0, 0) |
| 1581 | if err != nil { |
| 1582 | return nil, err |
| 1583 | } |
| 1584 | |
| 1585 | return io.NopCloser(args.Content), nil |
| 1586 | } |
| 1587 | |
| 1588 | // Set the various headers |
| 1589 | if args.UID > -1 { |
| 1590 | req.Header.Set("X-Incus-uid", fmt.Sprintf("%d", args.UID)) |
| 1591 | } |
| 1592 | |
| 1593 | if args.GID > -1 { |
nothing calls this directly
no test coverage detected