Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Di/ios provider/file and logs/qa 16207 #119

Merged
merged 9 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/units/base-device/support/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import request from 'postman-request'
import logger from '../../../util/logger.js'
export default syrup.serial()
.define(options => {
const log = logger.createLogger('evice:support:storage')
const log = logger.createLogger('device:support:storage')
let plugin = Object.create(null)
plugin.store = function(type, stream, meta) {
let resolver = Promise.defer()
Expand Down
7 changes: 6 additions & 1 deletion lib/units/ios-device/plugins/devicelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default syrup.serial()
let threadId = 0
let processId = 0
let subsystem = '*'
let timestamp = new Date().getTime() / 1000
let message
logs.forEach(log => {
let logLevel = 2
Expand Down Expand Up @@ -71,6 +72,10 @@ export default syrup.serial()
processId = log.processID
}

if (log.timestamp) {
timestamp = log.timestamp
}

if (log.subsystem) {
subsystem = log.subsystem
}
Expand All @@ -82,7 +87,7 @@ export default syrup.serial()
realGroup.group
, wireutil.envelope(new wire.DeviceLogcatEntryMessage(
options.serial
, new Date().getTime() / 1000
, Date.parse(timestamp) / 1000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value of timestamp in case no timestamp could be found from the log line entry is not parseable
image

, processId
, threadId
, logLevel
Expand Down
42 changes: 17 additions & 25 deletions lib/units/ios-device/plugins/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import wireutil from '../../../wire/util.js'
import router from '../../base-device/support/router.js'
import push from '../../base-device/support/push.js'
import storage from '../../base-device/support/storage.js'
import {exec} from 'child_process'
import {execFile} from 'child_process'
import path from 'path'
import fs from 'fs'
import {v4 as uuidv4} from 'uuid'
export default syrup.serial()
.dependency(router)
.dependency(push)
Expand All @@ -16,31 +17,24 @@ export default syrup.serial()
const log = logger.createLogger('device:plugins:filesystem')
let plugin = Object.create(null)

const getRootDir = dir => {
const getIdbTarget = dir => {
let currentPath = dir.split('/')
let rootDir = currentPath[1]
let target = 'media'
switch (rootDir) {
case 'root': {
// only for simulators
return 'root'
}
case 'application': {
return 'application'
}
case 'crashes': {
return 'crashes'
if (['root', 'application', 'crashes'].indexOf(rootDir) !== -1) {
return rootDir
}
else {
return 'media'
}
return target
}

router.on(wire.FileSystemGetMessage, function(channel, message) {
let reply = wireutil.reply(options.serial)
let file = message.file
log.info('Retrieving file "%s"', file)
let currentPath = file.split('/')
let target = getRootDir(file)
let target = getIdbTarget(file)
let tempFileName = `tmp_${uuidv4()}`

if (currentPath.length === 2) {
currentPath = ''
Expand All @@ -49,8 +43,7 @@ export default syrup.serial()
currentPath = currentPath.slice(2).join('/').replace(' ', '\\ ')
}

exec(
`idb file pull --${target} ./${currentPath} /tmp/tmp123 --json --udid ${options.serial}`,
execFile('idb', ['file', 'pull', `--${target}`, currentPath, `/tmp/${tempFileName}`, '--json', '--udid', options.serial],
(error, stdout, stderr) => {
if (error) {
log.warn('Unable to list directory "%s"', file, stderr)
Expand All @@ -72,7 +65,7 @@ export default syrup.serial()
, reply.fail('error', e)
])
}
fs.unlink('/tmp/tmp123', (err) => {
fs.unlink(`/tmp/${tempFileName}`, (err) => {
log.warn('Error while deleting file "%s"', file, err)
})
})
Expand All @@ -96,7 +89,7 @@ export default syrup.serial()
])
}
let currentPath = message.dir.split('/')
let target = getRootDir(message.dir)
let target = getIdbTarget(message.dir)

if (currentPath.length === 2) {
currentPath = ''
Expand All @@ -105,8 +98,7 @@ export default syrup.serial()
currentPath = currentPath.slice(2).join('/').replace(' ', '\\ ')
}

exec(
`idb file list --${target} ./${currentPath} --json --udid ${options.serial}`,
execFile('idb', ['file', 'list', `--${target}`, currentPath, '--json', '--udid', options.serial],
(error, stdout, stderr) => {
if (error) {
log.warn('Unable to list directory "%s"', message.dir, stderr)
Expand All @@ -118,21 +110,21 @@ export default syrup.serial()
}

let rawDirs = JSON.parse(stdout)
let dirs = []
let entries = []
rawDirs.forEach(dir => {
let name = dir.path
let mode = 16629
let mode = 0o40365
if (name.includes('.')) {
mode = 0o555
}
dirs.push({
entries.push({
name: name, mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: mode, size: 0
})
})

push.send([
channel
, reply.okay('success', dirs)
, reply.okay('success', entries)
])
}
)
Expand Down
17 changes: 0 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.