@@ -144,6 +144,19 @@ func (r *InstanceService) Start(ctx context.Context, id string, opts ...option.R
144144 return
145145}
146146
147+ // Returns information about a path in the guest filesystem. Useful for checking if
148+ // a path exists, its type, and permissions before performing file operations.
149+ func (r * InstanceService ) Stat (ctx context.Context , id string , query InstanceStatParams , opts ... option.RequestOption ) (res * PathInfo , err error ) {
150+ opts = slices .Concat (r .Options , opts )
151+ if id == "" {
152+ err = errors .New ("missing required id parameter" )
153+ return
154+ }
155+ path := fmt .Sprintf ("instances/%s/stat" , id )
156+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , query , & res , opts ... )
157+ return
158+ }
159+
147160// Stop instance (graceful shutdown)
148161func (r * InstanceService ) Stop (ctx context.Context , id string , opts ... option.RequestOption ) (res * Instance , err error ) {
149162 opts = slices .Concat (r .Options , opts )
@@ -277,6 +290,41 @@ func (r *InstanceNetwork) UnmarshalJSON(data []byte) error {
277290 return apijson .UnmarshalRoot (data , r )
278291}
279292
293+ type PathInfo struct {
294+ // Whether the path exists
295+ Exists bool `json:"exists,required"`
296+ // True if this is a directory
297+ IsDir bool `json:"is_dir"`
298+ // True if this is a regular file
299+ IsFile bool `json:"is_file"`
300+ // True if this is a symbolic link (only set when follow_links=false)
301+ IsSymlink bool `json:"is_symlink"`
302+ // Symlink target path (only set when is_symlink=true)
303+ LinkTarget string `json:"link_target,nullable"`
304+ // File mode (Unix permissions)
305+ Mode int64 `json:"mode"`
306+ // File size in bytes
307+ Size int64 `json:"size"`
308+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
309+ JSON struct {
310+ Exists respjson.Field
311+ IsDir respjson.Field
312+ IsFile respjson.Field
313+ IsSymlink respjson.Field
314+ LinkTarget respjson.Field
315+ Mode respjson.Field
316+ Size respjson.Field
317+ ExtraFields map [string ]respjson.Field
318+ raw string
319+ } `json:"-"`
320+ }
321+
322+ // Returns the unmodified JSON received from the API
323+ func (r PathInfo ) RawJSON () string { return r .JSON .raw }
324+ func (r * PathInfo ) UnmarshalJSON (data []byte ) error {
325+ return apijson .UnmarshalRoot (data , r )
326+ }
327+
280328type VolumeMount struct {
281329 // Path where volume is mounted in the guest
282330 MountPath string `json:"mount_path,required"`
@@ -422,3 +470,19 @@ const (
422470 InstanceLogsParamsSourceVmm InstanceLogsParamsSource = "vmm"
423471 InstanceLogsParamsSourceHypeman InstanceLogsParamsSource = "hypeman"
424472)
473+
474+ type InstanceStatParams struct {
475+ // Path to stat in the guest filesystem
476+ Path string `query:"path,required" json:"-"`
477+ // Follow symbolic links (like stat vs lstat)
478+ FollowLinks param.Opt [bool ] `query:"follow_links,omitzero" json:"-"`
479+ paramObj
480+ }
481+
482+ // URLQuery serializes [InstanceStatParams]'s query parameters as `url.Values`.
483+ func (r InstanceStatParams ) URLQuery () (v url.Values , err error ) {
484+ return apiquery .MarshalWithSettings (r , apiquery.QuerySettings {
485+ ArrayFormat : apiquery .ArrayQueryFormatComma ,
486+ NestedFormat : apiquery .NestedQueryFormatBrackets ,
487+ })
488+ }
0 commit comments