mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Clean up the filesystem plugin a little.
This commit is contained in:
parent
2d73310aa8
commit
a779413000
2 changed files with 76 additions and 86 deletions
|
@ -1,7 +1,4 @@
|
||||||
var util = require('util')
|
|
||||||
|
|
||||||
var syrup = require('stf-syrup')
|
var syrup = require('stf-syrup')
|
||||||
var adbkit = require('adbkit')
|
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
|
|
||||||
var logger = require('../../../util/logger')
|
var logger = require('../../../util/logger')
|
||||||
|
@ -13,34 +10,28 @@ module.exports = syrup.serial()
|
||||||
.dependency(require('../support/router'))
|
.dependency(require('../support/router'))
|
||||||
.dependency(require('../support/push'))
|
.dependency(require('../support/push'))
|
||||||
.dependency(require('../support/storage'))
|
.dependency(require('../support/storage'))
|
||||||
.dependency(require('../resources/minicap'))
|
.define(function(options, adb, router, push, storage) {
|
||||||
.dependency(require('./util/display'))
|
|
||||||
.define(function(options, adb, router, push, storage, minicap, display) {
|
|
||||||
var log = logger.createLogger('device:plugins:filesystem')
|
var log = logger.createLogger('device:plugins:filesystem')
|
||||||
var plugin = Object.create(null)
|
var plugin = Object.create(null)
|
||||||
|
|
||||||
plugin.retrieve = function(file) {
|
plugin.retrieve = function(file) {
|
||||||
log.info('Retriving file %s', file)
|
log.info('Retrieving file "%s"', file)
|
||||||
|
|
||||||
return adb.stat(options.serial, file)
|
return adb.stat(options.serial, file)
|
||||||
.then(function(stats) {
|
.then(function(stats) {
|
||||||
if (stats.size == 0){
|
|
||||||
log.info(util.format("File %s is empty", file))
|
|
||||||
}
|
|
||||||
|
|
||||||
return adb.pull(options.serial, file)
|
return adb.pull(options.serial, file)
|
||||||
.then(function(transfer) {
|
.then(function(transfer) {
|
||||||
// if this is a new store type, somethings need add to units/storage/plugins/
|
// We may have add new storage plugins for various file types
|
||||||
|
// in the future, and add proper detection for the mimetype.
|
||||||
|
// But for now, let's just use application/octet-stream for
|
||||||
|
// everything like it's 2001.
|
||||||
return storage.store('blob', transfer, {
|
return storage.store('blob', transfer, {
|
||||||
filename: path.basename(file),
|
filename: path.basename(file)
|
||||||
contentType: 'application/octet-stream', // FIXME(ssx): need to detect file type
|
, contentType: 'application/octet-stream'
|
||||||
knownLength: stats.size
|
, knownLength: stats.size
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.finally(function(){
|
|
||||||
log.info(util.format("File %s transfer finished", file))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
router.on(wire.FileSystemGetMessage, function(channel, message) {
|
router.on(wire.FileSystemGetMessage, function(channel, message) {
|
||||||
|
@ -48,15 +39,15 @@ module.exports = syrup.serial()
|
||||||
plugin.retrieve(message.file)
|
plugin.retrieve(message.file)
|
||||||
.then(function(file) {
|
.then(function(file) {
|
||||||
push.send([
|
push.send([
|
||||||
channel,
|
channel
|
||||||
reply.okay('success', file)
|
, reply.okay('success', file)
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
log.error('File retrieve %s failed\n%s', message.file, err.stack)
|
log.warn('Unable to retrieve "%s"', message.file, err.stack)
|
||||||
push.send([
|
push.send([
|
||||||
channel,
|
channel
|
||||||
reply.fail(err.message)
|
, reply.fail(err.message)
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -66,17 +57,18 @@ module.exports = syrup.serial()
|
||||||
adb.readdir(options.serial, message.dir)
|
adb.readdir(options.serial, message.dir)
|
||||||
.then(function(files) {
|
.then(function(files) {
|
||||||
push.send([
|
push.send([
|
||||||
channel,
|
channel
|
||||||
reply.okay('success', files)
|
, reply.okay('success', files)
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
log.error('Dir list %s failed\n%s', message.dir, err.stack)
|
log.warn('Unable to list directory "%s"', message.dir, err.stack)
|
||||||
push.send([
|
push.send([
|
||||||
channel,
|
channel
|
||||||
reply.fail(err.message)
|
, reply.fail(err.message)
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
return plugin;
|
|
||||||
|
return plugin
|
||||||
})
|
})
|
||||||
|
|
|
@ -20,11 +20,9 @@
|
||||||
i.fa.fa-file-o(ng-hide='f.mode|isdir')
|
i.fa.fa-file-o(ng-hide='f.mode|isdir')
|
||||||
td
|
td
|
||||||
button.btn.btn-sm.btn-primary-outline(
|
button.btn.btn-sm.btn-primary-outline(
|
||||||
ng-click='dirEnter(f.name)', ng-show='f.mode|isdir')
|
ng-click='dirEnter(f.name)', ng-show='f.mode|isdir') {{f.name}}
|
||||||
{{f.name}}
|
|
||||||
button.btn.btn-sm.btn-primary-outline(
|
button.btn.btn-sm.btn-primary-outline(
|
||||||
ng-click='getFile(f.name)', ng-hide='f.mode|isdir')
|
ng-click='getFile(f.name)', ng-hide='f.mode|isdir') {{f.name}}
|
||||||
{{f.name}}
|
|
||||||
td
|
td
|
||||||
i {{f.mode|mode2unix}}
|
i {{f.mode|mode2unix}}
|
||||||
td {{f.size}}
|
td {{f.size}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue