Skip to content

Commit

Permalink
Bugfix: could not locate session file due to ppid changes when runnin…
Browse files Browse the repository at this point in the history
…g it with wrapper scripts
  • Loading branch information
iychoi committed Jun 9, 2022
1 parent f6f85b0 commit 1e5c12b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKG=github.com/cyverse/gocommands
VERSION=v0.2.1
VERSION=v0.2.2
GIT_COMMIT?=$(shell git rev-parse HEAD)
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS?="-X '${PKG}/commons.clientVersion=${VERSION}' -X '${PKG}/commons.gitCommit=${GIT_COMMIT}' -X '${PKG}/commons.buildDate=${BUILD_DATE}'"
Expand All @@ -15,8 +15,22 @@ build:
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gocmd ./cmd/*.go


.PHONY: test-release
test-release:
rm -rf release

# amd64_linux
mkdir -p release/amd64_linux
cd install && ./prep-install-script.sh ../release/amd64_linux && cd ..
cd install && ./prep-shortcut-script.sh ../release/amd64_linux && cd ..
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=${LDFLAGS} -o release/amd64_linux/gocmd cmd/*.go
cd release/amd64_linux && tar cf gocommands_amd64_linux_${VERSION}.tar * && mv *.tar .. && cd ../..


.PHONY: build-release
build-release:
rm -rf release

# i386_linux
mkdir -p release/i386_linux
cd install && ./prep-install-script.sh ../release/i386_linux && cd ..
Expand Down
24 changes: 22 additions & 2 deletions commons/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
environmentMgr *irodsclient_icommands.ICommandsEnvironmentManager
account *irodsclient_types.IRODSAccount

sessionID int
resourceServer string
)

Expand Down Expand Up @@ -74,14 +75,15 @@ func SetCWD(cwd string) {
}

session.CurrentWorkingDir = filepath.Clean(cwd)
environmentMgr.SaveSession()
environmentMgr.SaveSession(sessionID)
}

func SetCommonFlags(command *cobra.Command) {
command.Flags().StringP("config", "c", "", "Set config file (default is $HOME/.irods/irods_environment.json)")
command.Flags().BoolP("version", "v", false, "Print version")
command.Flags().BoolP("help", "h", false, "Print help")
command.Flags().BoolP("debug", "d", false, "Enable debug mode")
command.Flags().Int32P("session", "s", -1, "Set session ID")
command.Flags().StringP("resource", "", "", "Set resource server")
}

Expand Down Expand Up @@ -129,6 +131,24 @@ func ProcessCommonFlags(command *cobra.Command) (bool, error) {
}
}

sessionFlag := command.Flags().Lookup("session")
if sessionFlag != nil {
// load to global variable
sessionIDString := sessionFlag.Value.String()
sessionIDInt, err := strconv.ParseInt(sessionIDString, 10, 32)
if err != nil {
logger.Error(err)
return false, err // stop here
}
sessionID = int(sessionIDInt)
}

if sessionID < 0 {
sessionID = os.Getppid()
}

logger.Debugf("use sessionID - %d", sessionID)

configFlag := command.Flags().Lookup("config")
if configFlag != nil {
config := configFlag.Value.String()
Expand Down Expand Up @@ -305,7 +325,7 @@ func loadConfigFile(command *cobra.Command, configFilePath string) error {
return err
}

err = iCommandsEnvMgr.Load()
err = iCommandsEnvMgr.Load(sessionID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cyverse/gocommands
go 1.17

require (
github.com/cyverse/go-irodsclient v0.9.3
github.com/cyverse/go-irodsclient v0.9.4-0.20220609195211-94e54487aea5
github.com/jedib0t/go-pretty/v6 v6.3.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cyverse/go-irodsclient v0.9.3 h1:ERfEZJYOH8ZvAceKD68iCfesWyMyqGf/VBVUwxudD9Y=
github.com/cyverse/go-irodsclient v0.9.3/go.mod h1:vEllPYPlJhNUp/op6e4/zDKt/wOIeN8Y7Nyy4QpR/F0=
github.com/cyverse/go-irodsclient v0.9.4-0.20220609195211-94e54487aea5 h1:filixIT8Lj1sdMfSaieG3A0jwhU90/QaBOLCrrU04YQ=
github.com/cyverse/go-irodsclient v0.9.4-0.20220609195211-94e54487aea5/go.mod h1:vEllPYPlJhNUp/op6e4/zDKt/wOIeN8Y7Nyy4QpR/F0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion install/prep-shortcut-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ main()

for i in "${SUBCOMMANDS[@]}"
do
echo -e "#!/bin/bash\nbaseDir=\$(dirname \"\$0\")\n\$baseDir/gocmd $i \$@" > $1/go$i
echo -e "#!/bin/bash\nbaseDir=\$(dirname \"\$0\")\n\$baseDir/gocmd -s \$PPID $i \$@" > $1/go$i
chmod 700 $1/go$i
done
}
Expand Down

0 comments on commit 1e5c12b

Please sign in to comment.