Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit b2f3b48

Browse files
author
Eddie Flores
committed
Work on detailed list.
1 parent abacae3 commit b2f3b48

File tree

1 file changed

+130
-2
lines changed

1 file changed

+130
-2
lines changed

lib/ssh-adapter.js

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,32 @@ module.exports = CoreObject.extend({
2424
},
2525

2626
list: function() {
27-
return this._list().then(this._printRevisions.bind(this));
27+
var _this = this;
28+
return new Promise(function (resolve, reject) {
29+
_this._list().then(function (list) {
30+
console.log('Got this list ');
31+
_this._printRevisions(list).then(function () {
32+
console.log('Print revisions ended');
33+
});
34+
}, function (error) {
35+
console.error('Got this error ', error);
36+
reject(error);
37+
});
38+
39+
// return this._list().then(this._printRevisions.bind(this));
40+
41+
// var listPromise = _this._list();
42+
43+
// listPromise.then(function (list) {
44+
// var printRevisions = _this._printRevisions(list);
45+
// printRevisions.then(function (data) {
46+
// console.log('Print revisions resolved');
47+
// resolve(data);
48+
// }, function (error) {
49+
// reject(error);
50+
// })
51+
// });
52+
});
2853
},
2954

3055
upload: function(buffer) {
@@ -85,12 +110,14 @@ module.exports = CoreObject.extend({
85110
};
86111

87112
var startFind = function (resolve, reject) {
113+
88114
conn.on('ready', function () {
89115
findRevisions(function (error, list) {
90116
if (error) {
91117
return reject(error);
92118
}
93119
resolve(list);
120+
conn.end();
94121
});
95122
});
96123

@@ -275,14 +302,115 @@ module.exports = CoreObject.extend({
275302

276303
return new Promise(startUpload);
277304
},
305+
306+
307+
308+
309+
310+
311+
312+
313+
314+
315+
316+
317+
318+
319+
320+
321+
322+
323+
324+
278325

279326
_printRevisions: function(list) {
280327
var header = 'Found the following revisions:';
328+
var remoteDir = this.config.remoteDir;
329+
var _this = this;
330+
var config = this.config;
331+
var conn = this.client;
332+
var filePromises = [];
333+
281334
var revisionsList = list.join('\n');
282335
// TODO: Print the details for each revisions (found in meta).
283-
return this._printSuccessMessage('\n' + header + '\n\n' + revisionsList + '\n');
336+
// return this._printSuccessMessage('\n' + header + '\n\n' + revisionsList + '\n');
337+
return new Promise(function (resolve, reject) {
338+
339+
/**
340+
* Reads a remote file. Returns a promise.
341+
*/
342+
var readFile = function (metaPath, sftp, options) {
343+
344+
var promiseHandler = function (fileResolve, fileReject) {
345+
sftp.readFile(metaPath, options, function (error, data) {
346+
if (error) {
347+
fileReject(error);
348+
return;
349+
}
350+
console.log('Got this data ', data);
351+
fileResolve({filename: metaPath, data: data});
352+
});
353+
};
354+
return new Promise(promiseHandler);
355+
};
356+
357+
conn.on('ready', function () {
358+
359+
conn.sftp(function (error, sftp) {
360+
361+
list.forEach(function (revisionId) {
362+
var metaPath = remoteDir + revisionId + '/meta.json';
363+
filePromises.push(readFile(metaPath, sftp));
364+
});
365+
366+
Promise.all(filePromises).then(function (data) {
367+
console.log('Got those files')
368+
resolve(data);
369+
}, function (error) {
370+
console.error('Got an error with those files ', error);
371+
reject(error);
372+
});
373+
374+
}); // conn.sftp
375+
});
376+
377+
conn.on('error', function (error) {
378+
console.error('A connection error');
379+
reject(error);
380+
});
381+
382+
conn.connect({
383+
host: config.host,
384+
username: config.username,
385+
privateKey: require('fs').readFileSync(config.privateKeyFile),
386+
});
387+
388+
});
284389
},
285390

391+
392+
393+
394+
395+
396+
397+
398+
399+
400+
401+
402+
403+
404+
405+
406+
407+
408+
409+
410+
411+
412+
413+
286414
_printSuccessMessage: function (message) {
287415
return this.ui.writeLine(message);
288416
},

0 commit comments

Comments
 (0)