Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit179e2cc

Browse files
committed
expand
1 parent1b4157b commit179e2cc

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

‎agent/agent.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
10751075
//
10761076
// An example is VS Code Remote, which must know the directory
10771077
// before initializing a connection.
1078-
manifest.Directory,err=expandDirectory(manifest.Directory)
1078+
manifest.Directory,err=expandPathToAbs(manifest.Directory)
10791079
iferr!=nil {
10801080
returnxerrors.Errorf("expand directory: %w",err)
10811081
}
@@ -1119,13 +1119,18 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11191119
// scripts have completed.
11201120
varpostStartScripts []codersdk.WorkspaceAgentScript
11211121
for_,dc:=rangemanifest.Devcontainers {
1122+
dc=expandDevcontainerPaths(a.logger,dc)
11221123
// TODO(mafredri): Verify `@devcontainers/cli` presence.
11231124
// TODO(mafredri): Verify workspace folder exists.
11241125
// TODO(mafredri): If set, verify config path exists.
11251126
postStartScripts=append(postStartScripts,agentcontainers.DevcontainerStartupScript(dc))
11261127
}
11271128

1128-
err=a.scriptRunner.Init(manifest.Scripts,aAPI.ScriptCompleted,agentscripts.WithPostStartScripts(postStartScripts...))
1129+
err=a.scriptRunner.Init(
1130+
manifest.Scripts,
1131+
aAPI.ScriptCompleted,
1132+
agentscripts.WithPostStartScripts(postStartScripts...),
1133+
)
11291134
iferr!=nil {
11301135
returnxerrors.Errorf("init script runner: %w",err)
11311136
}
@@ -1864,30 +1869,42 @@ func userHomeDir() (string, error) {
18641869
returnu.HomeDir,nil
18651870
}
18661871

1867-
// expandDirectory converts a directory path to an absolute path.
1868-
// It primarily resolves the home directory and any environment
1869-
// variables that may be set
1870-
funcexpandDirectory(dirstring) (string,error) {
1871-
ifdir=="" {
1872+
// expandPathToAbs converts a path to an absolute path. It primarily resolves
1873+
// the home directory and any environment variables that may be set.
1874+
funcexpandPathToAbs(pathstring) (string,error) {
1875+
ifpath=="" {
18721876
return"",nil
18731877
}
1874-
ifdir[0]=='~' {
1878+
ifpath[0]=='~' {
18751879
home,err:=userHomeDir()
18761880
iferr!=nil {
18771881
return"",err
18781882
}
1879-
dir=filepath.Join(home,dir[1:])
1883+
path=filepath.Join(home,path[1:])
18801884
}
1881-
dir=os.ExpandEnv(dir)
1885+
path=os.ExpandEnv(path)
18821886

1883-
if!filepath.IsAbs(dir) {
1887+
if!filepath.IsAbs(path) {
18841888
home,err:=userHomeDir()
18851889
iferr!=nil {
18861890
return"",err
18871891
}
1888-
dir=filepath.Join(home,dir)
1892+
path=filepath.Join(home,path)
1893+
}
1894+
returnpath,nil
1895+
}
1896+
1897+
funcexpandDevcontainerPaths(logger slog.Logger,dc codersdk.WorkspaceAgentDevcontainer) codersdk.WorkspaceAgentDevcontainer {
1898+
varerrerror
1899+
ifdc.WorkspaceFolder,err=expandPathToAbs(dc.WorkspaceFolder);err!=nil {
1900+
logger.Warn(context.Background(),"expand devcontainer workspace folder failed",slog.Error(err))
1901+
}
1902+
ifdc.ConfigPath!="" {
1903+
ifdc.ConfigPath,err=expandPathToAbs(dc.ConfigPath);err!=nil {
1904+
logger.Warn(context.Background(),"expand devcontainer config path failed",slog.Error(err))
1905+
}
18891906
}
1890-
returndir,nil
1907+
returndc
18911908
}
18921909

18931910
// EnvAgentSubsystem is the environment variable used to denote the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp