Skip to content

Commit da98609

Browse files
authored
Merge pull request #301 from achilleas-k/config-path
Less intrusive Windows paths
2 parents 4bc4863 + b3f76ed commit da98609

File tree

6 files changed

+61
-33
lines changed

6 files changed

+61
-33
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ matrix:
1919
os: linux
2020
- go: "1.14.x"
2121
os: osx
22+
osx_image: xcode12.2
2223
addons:
2324
homebrew:
2425
packages:

dorelease

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import re
1919
from glob import glob
2020
from subprocess import check_output, call, DEVNULL
2121
from tempfile import TemporaryDirectory
22-
import requests
2322
import plistlib
23+
import requests
2424
from requests.exceptions import ConnectionError as ConnError
2525

2626
DESTDIR = "dist"
@@ -71,8 +71,10 @@ def download(url, fname=None):
7171
except ConnError:
7272
print(f"Error while trying to download {url}", file=sys.stderr)
7373
print("Skipping.", file=sys.stderr)
74-
return
75-
size = int(req.headers.get("content-length"))
74+
return None
75+
size = 0
76+
if sizestr := req.headers.get("content-length"):
77+
size = int(sizestr)
7678
etag = req.headers.get("etag")
7779
oldet = ETAGS.get(url)
7880
if etag == oldet and os.path.exists(fname):
@@ -215,15 +217,6 @@ def debianize(binfile, annexsa_archive):
215217
"""
216218
For each Linux binary make a deb package with git annex standalone.
217219
"""
218-
def docker_cleanup():
219-
print("Stopping and cleaning up docker container")
220-
cmd = ["docker", "kill", "gin-deb-build"]
221-
run(cmd)
222-
cmd = ["docker", "container", "rm", "gin-deb-build"]
223-
run(cmd)
224-
225-
docker_cleanup()
226-
227220
# The default temporary root on macOS is /var/folders
228221
# Docker currently has issues mounting directories under /var
229222
# Forcing temporary directory to be rooted at /tmp instead
@@ -316,7 +309,6 @@ def debianize(binfile, annexsa_archive):
316309
print("Running debian build script")
317310
if run(cmd) > 0:
318311
print("Deb build failed", file=sys.stderr)
319-
docker_cleanup()
320312
return
321313

322314
debfilename = f"{pkgname}.deb"
@@ -326,7 +318,6 @@ def debianize(binfile, annexsa_archive):
326318
os.remove(debfiledest)
327319
shutil.copy(debfilepath, debfiledest)
328320
print("Done")
329-
docker_cleanup()
330321
return debfiledest
331322

332323

@@ -448,19 +439,20 @@ def winbundle(binfile, git_pkg, annex_pkg):
448439
shutil.copy("README.md", pkgroot)
449440
shutil.copy(os.path.join("scripts", "gin-shell.bat"), pkgroot)
450441
shutil.copy(os.path.join("scripts", "set-global.bat"), pkgroot)
442+
shutil.copy(os.path.join("scripts", "gin.bat"), pkgroot)
451443

452444
gitdir = os.path.join(pkgroot, "git")
453445
os.makedirs(gitdir)
454446

455447
# extract git portable and annex into git dir
456-
cmd = ["7z", "x", f"-o{gitdir}", git_pkg]
448+
cmd = ["7z", "x", "-y", f"-o{gitdir}", git_pkg]
457449
print(f"Running {' '.join(cmd)}")
458450
if run(cmd, stdout=DEVNULL) > 0:
459451
print(f"Failed to extract git archive {git_pkg} to {gitdir}",
460452
file=sys.stderr)
461453
return None
462454

463-
cmd = ["7z", "x", f"-o{gitdir}", annex_pkg]
455+
cmd = ["7z", "x", "-y", f"-o{gitdir}", annex_pkg]
464456
print(f"Running {' '.join(cmd)}")
465457
if run(cmd, stdout=DEVNULL) > 0:
466458
print(f"Failed to extract git archive {annex_pkg} to {gitdir}",

ginclient/config/config.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"strconv"
99
"strings"
10+
"sync"
1011

1112
"github.com/G-Node/gin-cli/ginclient/log"
1213
"github.com/G-Node/gin-cli/gincmd/ginerrors"
@@ -51,7 +52,9 @@ var (
5152

5253
// configuration cache: used to avoid rereading during a single command invocation
5354
configuration GinCliCfg
54-
set = false
55+
56+
// configReadOnce to read config only once per run
57+
configReadOnce sync.Once
5558
)
5659

5760
// Types
@@ -114,9 +117,11 @@ type GinCliCfg struct {
114117
// Read loads in the configuration from the config file(s), merges any defined values into the default configuration, and returns a populated GinConfiguration struct.
115118
// The configuration is cached. Subsequent reads reuse the already loaded configuration.
116119
func Read() GinCliCfg {
117-
if set {
118-
return configuration
119-
}
120+
configReadOnce.Do(read)
121+
return configuration
122+
}
123+
124+
func read() {
120125
viper.Reset()
121126
viper.SetTypeByDefaultValue(true)
122127

@@ -155,9 +160,6 @@ func Read() GinCliCfg {
155160
path, _ := filepath.Split(configuration.Bin.GitAnnex)
156161
configuration.Bin.GitAnnexPath = path
157162
}
158-
159-
set = true
160-
return configuration
161163
}
162164

163165
func removeInvalidServerConfs() {
@@ -200,7 +202,7 @@ func SetConfig(key string, value interface{}) error {
200202
v.Set(key, value)
201203
v.WriteConfig()
202204
// invalidate the read cache
203-
set = false
205+
configReadOnce = sync.Once{}
204206
return nil
205207
}
206208

@@ -223,7 +225,8 @@ func RmServerConf(alias string) {
223225
delete(c.Servers, alias)
224226
v.Set("servers", c.Servers)
225227
v.WriteConfig()
226-
set = false
228+
// invalidate the read cache
229+
configReadOnce = sync.Once{}
227230
}
228231

229232
// SetDefaultServer writes the given name to the config file to server as the default server for web calls.

scripts/gin.bat

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
:: GIN client entry point for Windows
2+
::
3+
:: This file should be part of the gin client Windows bundle.
4+
::
5+
:: The purpose of the file is to act as a wrapper for the GIN CLI binary. It
6+
:: sets the path to use the bundled dependencies without polluting the user's
7+
:: permanent global path.
8+
9+
10+
@echo off
11+
12+
setlocal
13+
set gindir=%~dp0
14+
set ginpaths=%gindir%bin;%gindir%git\usr\bin;%gindir%git\bin
15+
set path=%ginpaths%;%path%
16+
17+
gin.exe %*
18+
endlocal

scripts/set-global.bat

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
:: GIN client global setup for Windows
2-
::
2+
::
33
:: This file should be part of the gin client Windows bundle. The purpose of
44
:: the file is to permanently change the user path environment to be able to
55
:: run GIN commands from the command line (cmd and PowerShell).
66

7-
echo off
7+
@echo off
88

9-
set curdir=%~dp0
9+
set ginpath=%~dp0
10+
11+
:: Get user path *only* (No system path)
12+
for /F "skip=2 tokens=1,2*" %%N in ('%SystemRoot%\System32\reg.exe query "HKCU\Environment" /v "Path" 2^>nul') do if /I "%%N" == "Path" call set "userpath=%%P"
13+
14+
echo "Checking"
15+
echo %userpath%|find /I "gin">nul && (
16+
echo Please edit the "Path" variable and remove all previous GIN CLI paths.
17+
echo The environment variables settings window will open automatically.
18+
pause
19+
rundll32 sysdm.cpl,EditEnvironmentVariables
20+
)
21+
22+
:: Read again
23+
for /F "skip=2 tokens=1,2*" %%N in ('%SystemRoot%\System32\reg.exe query "HKCU\Environment" /v "Path" 2^>nul') do if /I "%%N" == "Path" call set "userpath=%%P"
24+
25+
:: Prepend GIN path
26+
echo Prepending "%ginpath%;" to path
27+
setx path "%ginpath%;%userpath%"
1028

11-
set ginbinpath=%curdir%\bin
12-
set gitpaths=%curdir%\git\usr\bin;%curdir%\git\bin
13-
echo Appending "%ginbinpath%;%gitpaths%" to path
14-
echo %path%|find /I "%curdir%">nul || setx path "%path%;%ginbinpath%;%gitpaths%"
1529
echo GIN CLI is ready
1630
pause

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.11
1+
version=1.12dev

0 commit comments

Comments
 (0)