forked from DeviceFarmer/stf
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
38fed00
add log parsing by tags
5c5f9fc
remake install
f58f3d1
implement storage navigation
b58d961
beatify
3e24c6f
Merge remote-tracking branch 'github/master' into di/ios-provider/fil…
976e6a0
fix name in log
b85bc6e
Update lib/units/ios-device/plugins/filesystem.js
DaniilSmirnov 9cd7343
Merge remote-tracking branch 'github/di/ios-provider/file-and-logs/QA…
e32d87e
review fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import syrup from '@devicefarmer/stf-syrup' | ||
import logger from '../../../util/logger.js' | ||
import wire from '../../../wire/index.js' | ||
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 path from 'path' | ||
import fs from 'fs' | ||
export default syrup.serial() | ||
.dependency(router) | ||
.dependency(push) | ||
.dependency(storage) | ||
.define(function(options, router, push, storage) { | ||
const log = logger.createLogger('device:plugins:filesystem') | ||
let plugin = Object.create(null) | ||
|
||
const getRootDir = dir => { | ||
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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' | ||
} | ||
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return target | ||
} | ||
DaniilSmirnov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) | ||
|
||
if (currentPath.length === 2) { | ||
currentPath = '' | ||
} | ||
else { | ||
currentPath = currentPath.slice(2).join('/').replace(' ', '\\ ') | ||
} | ||
|
||
exec( | ||
`idb file pull --${target} ./${currentPath} /tmp/tmp123 --json --udid ${options.serial}`, | ||
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(error, stdout, stderr) => { | ||
if (error) { | ||
log.warn('Unable to list directory "%s"', file, stderr) | ||
} | ||
|
||
storage.store('blob', path.basename(file), { | ||
filename: path.basename(file) | ||
, contentType: 'application/octet-stream' | ||
}).then((file) => { | ||
try { | ||
push.send([ | ||
channel | ||
, reply.okay('success', file) | ||
]) | ||
} | ||
catch (e) { | ||
push.send([ | ||
channel | ||
, reply.fail('error', e) | ||
]) | ||
} | ||
fs.unlink('/tmp/tmp123', (err) => { | ||
log.warn('Error while deleting file "%s"', file, err) | ||
}) | ||
}) | ||
} | ||
) | ||
}) | ||
router.on(wire.FileSystemListMessage, function(channel, message) { | ||
let reply = wireutil.reply(options.serial) | ||
let dirs = [] | ||
let rootDir = message.dir | ||
if (rootDir === '/') { | ||
dirs = [ | ||
{name: 'root', mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: 16877, size: 0} | ||
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
, {name: 'application', mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: 16877, size: 0} | ||
, {name: 'crashes', mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: 16877, size: 0} | ||
, {name: 'media', mtime: '1970-01-01T00:00:00.000Z', atime: null, ctime: null, birthtime: null, mode: 16877, size: 0} | ||
] | ||
push.send([ | ||
channel | ||
, reply.okay('success', dirs) | ||
]) | ||
} | ||
let currentPath = message.dir.split('/') | ||
let target = getRootDir(message.dir) | ||
|
||
if (currentPath.length === 2) { | ||
currentPath = '' | ||
} | ||
else { | ||
currentPath = currentPath.slice(2).join('/').replace(' ', '\\ ') | ||
} | ||
|
||
exec( | ||
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`idb file list --${target} ./${currentPath} --json --udid ${options.serial}`, | ||
(error, stdout, stderr) => { | ||
if (error) { | ||
log.warn('Unable to list directory "%s"', message.dir, stderr) | ||
push.send([ | ||
channel | ||
, reply.fail(error.message) | ||
]) | ||
return | ||
} | ||
|
||
let rawDirs = JSON.parse(stdout) | ||
let dirs = [] | ||
rawDirs.forEach(dir => { | ||
let name = dir.path | ||
let mode = 16629 | ||
if (name.includes('.')) { | ||
mode = 0o555 | ||
} | ||
dirs.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) | ||
irdkwmnsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]) | ||
} | ||
) | ||
}) | ||
return plugin | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--style json
is unrecognized on an iphone with ios 18.1.1 and idb-companion 1.1.8