Skip to content

Commit 86ba3d7

Browse files
authored
JBDS-4462 Change cache location for downloaded files(#812)
1 parent f231d09 commit 86ba3d7

11 files changed

Lines changed: 63 additions & 34 deletions

File tree

browser/model/installable-item.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import Logger from '../services/logger';
55
import path from 'path';
66
import fs from 'fs-extra';
77
import Downloader from './helpers/downloader';
8-
let remote = require('electron').remote;
8+
import {remote} from 'electron';
9+
import mkdirp from 'mkdirp';
910

1011
let ipcRenderer = require('electron').ipcRenderer;
1112

@@ -48,8 +49,10 @@ class InstallableItem {
4849
this.selectedOption = requirement.defaultOption ? requirement.defaultOption : 'install';
4950

5051
this.downloader = null;
51-
this.downloadFolder = this.installerDataSvc.tempDir();
52-
this.downloadedFile = path.join(this.installerDataSvc.tempDir(), fileName);
52+
this.downloadFolder = path.join(this.installerDataSvc.localAppData(), 'cache');
53+
mkdirp.sync(this.downloadFolder);
54+
this.downloadedFile = path.join(this.downloadFolder, fileName);
55+
5356
this.installAfter = undefined;
5457
this.ipcRenderer = ipcRenderer;
5558
this.authRequired = authRequired;

browser/services/data.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,22 @@ class InstallerDataService {
189189
return this.tmpDir;
190190
}
191191

192+
localAppData() {
193+
let appData = Platform.identify({
194+
win32: ()=> {
195+
let appDataPath = Platform.ENV.APPDATA;
196+
return appDataPath ? path.join(appDataPath, '..', 'Local', 'RedHat', 'DevSuite') : this.tempDir();
197+
}, darwin: ()=> {
198+
let homePath = Platform.ENV.HOME;
199+
return homePath ? path.join(homePath , 'Library', 'Application Support', 'RedHat', 'DevSuite') : this.tempDir();
200+
}, default: ()=> {
201+
return this.tempDir();
202+
}
203+
});
204+
return path.resolve(appData);
205+
}
206+
207+
192208
isDownloading() {
193209
return this.downloading;
194210
}

test/unit/model/cdk-test.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('CDK installer', function() {
2727

2828
installerDataSvc = sinon.stub(new InstallerDataService());
2929
installerDataSvc.getRequirementByName.restore();
30+
installerDataSvc.localAppData.restore();
3031
installerDataSvc.tempDir.returns('temporaryFolder');
3132
installerDataSvc.installDir.returns('installFolder');
3233
installerDataSvc.getUsername.returns('user');
@@ -121,10 +122,10 @@ describe('CDK installer', function() {
121122
}
122123
}
123124
},
124-
{
125-
createCwd: false,
126-
createTmp: false
127-
});
125+
{
126+
createCwd: false,
127+
createTmp: false
128+
});
128129
installer = new CDKInstall(installerDataSvc, 'folderName', cdkUrl, 'installFile.exe', 'sha1');
129130
installer.ipcRenderer = { on: function() {} };
130131
sandbox = sinon.sandbox.create();
@@ -241,9 +242,9 @@ describe('CDK installer', function() {
241242
installer.installAfterRequirements(fakeProgress, resolve, reject);
242243
}).then(()=> {
243244
expect(Installer.prototype.exec).to.have.been.calledWith(
244-
path.join('ocBinRoot', 'minishift.exe') + ' setup-cdk --force --default-vm-driver=virtualbox',
245-
{PATH:''}
246-
);
245+
path.join('ocBinRoot', 'minishift.exe') + ' setup-cdk --force --default-vm-driver=virtualbox',
246+
{PATH:''}
247+
);
247248
expect(installer.createEnvironment).to.have.been.called;
248249
});
249250
});
@@ -256,9 +257,9 @@ describe('CDK installer', function() {
256257
installer.installAfterRequirements(fakeProgress, resolve, reject);
257258
}).then(()=> {
258259
expect(Installer.prototype.exec).to.have.been.calledWith(
259-
path.join('ocBinRoot', 'minishift.exe') + ' setup-cdk --force --default-vm-driver=hyperv',
260-
{PATH:''}
261-
);
260+
path.join('ocBinRoot', 'minishift.exe') + ' setup-cdk --force --default-vm-driver=hyperv',
261+
{PATH:''}
262+
);
262263
expect(installer.createEnvironment).to.have.been.called;
263264
});
264265
});

test/unit/model/cygwin-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('Cygwin installer', function() {
3737
installerDataSvc.installDir.returns('installationFolder');
3838
installerDataSvc.cygwinDir.returns('install/Cygwin');
3939
installerDataSvc.getInstallable.returns(fakeInstallable);
40+
installerDataSvc.localAppData.restore();
4041

4142
let fakeProgress;
4243

@@ -91,7 +92,7 @@ describe('Cygwin installer', function() {
9192

9293
it('should download cygwin installer to temporary folder as ssh-rsync.zip', function() {
9394
expect(new CygwinInstall(installerDataSvc, 'cygwin', 'url', 'cygwin.exe', 'sha').downloadedFile).to.equal(
94-
path.join('tempDirectory', 'cygwin.exe'));
95+
path.join(installerDataSvc.localAppData(), 'cache', 'cygwin.exe'));
9596
});
9697

9798
describe('installer download', function() {
@@ -116,7 +117,7 @@ describe('Cygwin installer', function() {
116117

117118
expect(streamSpy).to.have.been.calledOnce;
118119
expect(spy).to.have.been.calledOnce;
119-
expect(spy).to.have.been.calledWith(path.join('tempDirectory', 'cygwin.exe'));
120+
expect(spy).to.have.been.calledWith(path.join(installerDataSvc.localAppData(), 'cache', 'cygwin.exe'));
120121
});
121122

122123
it('should call a correct downloader request with the specified parameters once', function() {

test/unit/model/devstudio-test.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('devstudio installer', function() {
3737
name: 'OpenJDK'
3838
}
3939
};
40-
let packageJson = {version: "X.0.0-GA"};
40+
let packageJson = {version: 'X.0.0-GA'};
4141
let ds = sinon.stub(new InstallerDataService({}, reqsJson, packageJson));
4242
ds.getRequirementByName.restore();
4343
ds.tempDir.returns('tempDirectory');
@@ -48,6 +48,7 @@ describe('devstudio installer', function() {
4848
ds.getInstallable.returns(fakeInstall);
4949
ds.getUsername.returns('user');
5050
ds.getPassword.returns('passwd');
51+
ds.localAppData.restore();
5152
return ds;
5253
}
5354

@@ -100,7 +101,7 @@ describe('devstudio installer', function() {
100101

101102
it('should download devstudio installer to temporary folder with configured filename', function() {
102103
expect(new DevstudioInstall(DevstudioInstall.KEY, installerDataSvc, 'dev-studio', 'url', 'devstudio.jar').downloadedFile).to.equal(
103-
path.join('tempDirectory', 'devstudio.jar'));
104+
path.join(installerDataSvc.localAppData(), 'cache', 'devstudio.jar'));
104105
});
105106

106107
describe('installer download', function() {
@@ -126,7 +127,7 @@ describe('devstudio installer', function() {
126127

127128
expect(streamSpy).to.have.been.calledOnce;
128129
expect(spy).to.have.been.calledOnce;
129-
expect(spy).to.have.been.calledWith(path.join('tempDirectory', 'devstudio.jar'));
130+
expect(spy).to.have.been.calledWith(path.join(installerDataSvc.localAppData(), 'cache', 'devstudio.jar'));
130131
});
131132

132133
it('should call a correct downloader request with the specified parameters once', function() {
@@ -257,7 +258,7 @@ describe('devstudio installer', function() {
257258

258259
it('should perform headless install into the installation folder', function() {
259260
let spy = sandbox.spy(helper, 'execFile');
260-
let downloadedFile = path.join(installerDataSvc.tempDir(), 'devstudio.jar');
261+
let downloadedFile = path.join(installerDataSvc.localAppData(), 'cache', 'devstudio.jar');
261262
let javaPath = path.join(installerDataSvc.jdkDir(), 'bin', 'java');
262263
let javaOpts = [
263264
'-DTRACE=true',
@@ -267,10 +268,10 @@ describe('devstudio installer', function() {
267268
];
268269

269270
return installer.headlessInstall(helper)
270-
.then(() => {
271-
expect(spy).calledOnce;
272-
expect(spy).calledWith(javaPath, javaOpts);
273-
});
271+
.then(() => {
272+
expect(spy).calledOnce;
273+
expect(spy).calledWith(javaPath, javaOpts);
274+
});
274275
});
275276
});
276277
});

test/unit/model/jbosseap-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('jbosseap installer', function() {
5454
ds.getUsername.returns('user');
5555
ds.getPassword.returns('passwd');
5656
ds.devstudioDir.returns('installationFolder/devstudio');
57+
ds.localAppData.restore();
5758
return ds;
5859
}
5960

@@ -114,7 +115,7 @@ describe('jbosseap installer', function() {
114115

115116
it('should download jbosseap installer to temporary folder with configured filename', function() {
116117
expect(new JbosseapInstall(installerDataSvc, 'jbosseap', 'url', 'jbosseap.jar').downloadedFile).to.equal(
117-
path.join('tempDirectory', 'jbosseap.jar'));
118+
path.join(installerDataSvc.localAppData(), 'cache', 'jbosseap.jar'));
118119
});
119120

120121
it('should remove an existing folder with the same name', function() {
@@ -150,7 +151,7 @@ describe('jbosseap installer', function() {
150151

151152
expect(streamSpy).to.have.been.calledOnce;
152153
expect(spy).to.have.been.calledOnce;
153-
expect(spy).to.have.been.calledWith(path.join('tempDirectory', 'jbosseap.jar'));
154+
expect(spy).to.have.been.calledWith(path.join(installerDataSvc.localAppData(), 'cache', 'jbosseap.jar'));
154155
});
155156

156157
it('should call a correct downloader request with the specified parameters once', function() {
@@ -267,7 +268,7 @@ describe('jbosseap installer', function() {
267268

268269
it('should perform headless install into the installation folder', function() {
269270
let spy = sandbox.spy(helper, 'execFile');
270-
let downloadedFile = path.join(installerDataSvc.tempDir(), 'jbosseap.jar');
271+
let downloadedFile = path.join(installerDataSvc.localAppData(), 'cache', 'jbosseap.jar');
271272
let javaPath = path.join(installerDataSvc.jdkDir(), 'bin', 'java');
272273
let javaOpts = [
273274
'-DTRACE=true',

test/unit/model/jbossfuse-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('fuseplatform installer', function() {
6565
ds.getUsername.returns('user');
6666
ds.getPassword.returns('passwd');
6767
ds.devstudioDir.returns('installationFolder/devstudio');
68+
ds.localAppData.restore();
6869
return ds;
6970
}
7071

@@ -113,7 +114,7 @@ describe('fuseplatform installer', function() {
113114

114115
it('should download fuseplatform installer to temporary folder with configured filename', function() {
115116
expect(new FusePlatformInstall(installerDataSvc, 'fuseplatform', files).downloadedFile).to.equal(
116-
path.join('tempDirectory', files.platform.fileName));
117+
path.join(installerDataSvc.localAppData(), 'cache', files.platform.fileName));
117118
});
118119

119120
describe('installer download', function() {
@@ -139,7 +140,7 @@ describe('fuseplatform installer', function() {
139140

140141
expect(streamSpy).to.have.been.calledTwice;
141142
expect(spy).to.have.been.calledTwice;
142-
expect(spy).to.have.been.calledWith(path.join('tempDirectory', files.platform.fileName));
143+
expect(spy).to.have.been.calledWith(path.join(installerDataSvc.localAppData(), 'cache', files.platform.fileName));
143144
});
144145

145146
it('should call a correct downloader request with the specified parameters once', function() {

test/unit/model/jdk-install-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('JDK installer', function() {
3131
installerDataSvc.jdkDir.returns('install/jdk8');
3232
installerDataSvc.getUsername.returns('user');
3333
installerDataSvc.getPassword.returns('passwd');
34+
installerDataSvc.localAppData.restore();
3435

3536
let fakeProgress;
3637

@@ -101,7 +102,7 @@ describe('JDK installer', function() {
101102

102103
it('should download jdk installer to temporary folder with confiugured file name', function() {
103104
expect(new JdkInstall(installerDataSvc, 'jdk8', 'url', 'jdk.msi', 'sha').downloadedFile).to.equal(
104-
path.join('tempDirectory', 'jdk.msi'));
105+
path.join(installerDataSvc.localAppData(), 'cache', 'jdk.msi'));
105106
});
106107
});
107108

@@ -323,7 +324,7 @@ describe('JDK installer', function() {
323324
installer.downloadInstaller(fakeProgress, success, failure);
324325

325326
expect(spy).to.have.been.calledOnce;
326-
expect(spy).to.have.been.calledWith(path.join('tempDirectory', 'jdk.msi'));
327+
expect(spy).to.have.been.calledWith(path.join(installerDataSvc.localAppData(), 'cache', 'jdk.msi'));
327328
});
328329

329330
it('should call downloader#download with the specified parameters once', function() {

test/unit/model/kompose-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('kompose installer', function() {
3232
installerDataSvc.getUsername.returns('user');
3333
installerDataSvc.getPassword.returns('password');
3434
installerDataSvc.komposeDir.returns(path.join(installerDataSvc.installDir(), 'kompose'));
35+
installerDataSvc.localAppData.restore();
3536

3637
let installer;
3738

test/unit/model/virtualbox-test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('Virtualbox installer', function() {
3737
installerDataSvc.tempDir.returns('tempDirectory');
3838
installerDataSvc.installDir.returns('installationFolder');
3939
installerDataSvc.virtualBoxDir.returns('installationFolder/virtualbox');
40+
installerDataSvc.localAppData.restore();
4041

4142
let fakeProgress;
4243

@@ -90,7 +91,7 @@ describe('Virtualbox installer', function() {
9091

9192
it('should download virtualbox installer to temporary folder with name configured file name', function() {
9293
expect(new VirtualBoxInstall(installerDataSvc, 'virtualbox', 'url', 'virtualbox.exe', 'sha', 'ver', 'rev').downloadedFile).to.equal(
93-
path.join(installerDataSvc.tempDir(), 'virtualbox.exe'));
94+
path.join(installerDataSvc.localAppData(), 'cache', 'virtualbox.exe'));
9495
});
9596

9697
describe('installer download', function() {
@@ -113,7 +114,7 @@ describe('Virtualbox installer', function() {
113114
installer.downloadInstaller(fakeProgress, success, failure);
114115

115116
expect(spy).to.have.been.calledOnce;
116-
expect(spy).to.have.been.calledWith(path.join('tempDirectory', 'virtualbox.exe'));
117+
expect(spy).to.have.been.calledWith(path.join(installerDataSvc.localAppData(), 'cache', 'virtualbox.exe'));
117118
});
118119

119120
it('should call downloader#download with the specified parameters once', function() {
@@ -133,13 +134,14 @@ describe('Virtualbox installer', function() {
133134
});
134135

135136
describe('installation', function() {
136-
let downloadedFile = path.join('tempDirectory', 'virtualbox.exe');
137+
let downloadedFile;
137138
let helper;
138139

139140
describe('on macos', function() {
140141
beforeEach(function() {
141142
helper = new Installer('virtualbox', fakeProgress);
142143
sandbox.stub(Platform, 'getOS').returns('macOS');
144+
downloadedFile = path.join(installerDataSvc.localAppData(), 'cache', 'virtualbox.exe');
143145
installer = new VirtualBoxInstallDarwin(installerDataSvc, 'virtualbox', downloadUrl, 'virtualbox.exe', 'sha', version, revision);
144146
installer.ipcRenderer = {on: function() {}};
145147
});
@@ -155,6 +157,7 @@ describe('Virtualbox installer', function() {
155157
beforeEach(function() {
156158
helper = new Installer('virtualbox', fakeProgress);
157159
sandbox.stub(Platform, 'getOS').returns('win32');
160+
downloadedFile = path.join(installerDataSvc.localAppData(), 'cache', 'virtualbox.exe');
158161
installer = new VirtualBoxInstallWindows(installerDataSvc, 'virtualbox', downloadUrl, 'virtualbox.exe', 'sha', version, revision);
159162
installer.ipcRenderer = {on: function() {}};
160163
});

0 commit comments

Comments
 (0)