Skip to content

Commit

Permalink
Merge pull request appium#3859 from imurchie/isaac-ios-pullfile
Browse files Browse the repository at this point in the history
Fix pull file for iOS
  • Loading branch information
Jonahss committed Oct 20, 2014
2 parents 6dbb8e5 + 6b64212 commit 73362b5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 31 deletions.
19 changes: 15 additions & 4 deletions lib/devices/ios/ios-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,21 +507,32 @@ iOSController._getFullPath = function (remotePath, cb) {
}
}

if (remotePath.indexOf(appName) === 1) {
// de-absolutize the path
if (helpers.isWindows()) {
if (remotePath.indexof("://") === 1) {
remotePath = remotePath.slice(4);
}
} else {
if (remotePath.indexOf("/") === 0) {
remotePath = remotePath.slice(1);
}
}

if (remotePath.indexOf(appName) === 0) {
logger.debug("We want an app-relative file");

var findPath = basePath;
if (this.iOSSDKVersion >= 8) {
// the .app file appears in /Containers/Data and /Containers/Bundle both. We only want /Data
findPath = path.resolve(basePath, "Containers", "Data");
// the .app file appears in /Containers/Data and /Containers/Bundle both. We only want /Bundle
findPath = path.resolve(basePath, "Containers", "Bundle");
}
findPath = findPath.replace(/\s/g, '\\ ');

var findCmd = 'find ' + findPath + ' -name "' + appName + '"';
exec(findCmd, function (err, stdout) {
if (err) return cb(err);
var appRoot = stdout.replace(/\n$/, '');
var subPath = remotePath.substring(appName.length + 2);
var subPath = remotePath.substring(appName.length + 1);
fullPath = path.resolve(appRoot, subPath);
cb(null, fullPath);
}.bind(this));
Expand Down
65 changes: 38 additions & 27 deletions test/functional/ios/file-movement-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ describe('file movements - pullFile and pushFile', function () {
};
setup(this, desired).then(function (d) { driver = d; });

it('should not be able to fetch a file from the file system at large', function (done) {
driver
.pullFile(__filename)
.should.be.rejected
.nodeify(done);
});

it('should be able to fetch the Address book', function (done) {
driver
.pullFile('Library/AddressBook/AddressBook.sqlitedb')
Expand All @@ -28,12 +35,14 @@ describe('file movements - pullFile and pushFile', function () {
})
.nodeify(done);
});

it('should not be able to fetch something that does not exist', function (done) {
driver
.pullFile('Library/AddressBook/nothere.txt')
.should.eventually.be.rejectedWith(/13/)
.nodeify(done);
});

it('should be able to push and pull a file', function (done) {
var stringData = "random string data " + Math.random();
var base64Data = new Buffer(stringData).toString('base64');
Expand Down Expand Up @@ -79,7 +88,6 @@ describe('file movements - pullFile and pushFile', function () {
basePath = path.resolve(simRoots[0], 'Applications');
}
basePath = basePath.replace(/\s/g, '\\ ');

var findCmd = 'find ' + basePath + ' -name "TestApp.app"';
exec(findCmd, function (err, stdout) {
if (err) return done(err);
Expand All @@ -99,13 +107,7 @@ describe('file movements - pullFile and pushFile', function () {
}
});
});
after(function (done) {
if (fullPath) {
fs.unlink(fullPath, done);
} else {
done();
}
});

it('should be able to fetch a file from the app directory', function (done) {
var arg = path.resolve('/TestApp.app', fileName);
driver
Expand All @@ -117,34 +119,43 @@ describe('file movements - pullFile and pushFile', function () {
.nodeify(done);
});
});

describe('file movements - pullFolder', function () {
it('should pull all the files in Library/AddressBook', function (done) {
var entryCount = 0;
driver.pullFolder('Library/AddressBook')
.then(function (data) {
var zipStream = new Readable();
zipStream._read = function noop() {};
zipStream
.pipe(Unzip.Parse())
.on('entry', function (entry) {
entryCount++;
entry.autodrain();
})
.on('close', function () {
entryCount.should.be.above(1);
done();
});
driver
.pullFolder('Library/AddressBook')
.then(function (data) {
var zipStream = new Readable();
zipStream._read = function noop() {};
zipStream
.pipe(Unzip.Parse())
.on('entry', function (entry) {
entryCount++;
entry.autodrain();
})
.on('close', function () {
entryCount.should.be.above(1);
done();
});

zipStream.push(data, 'base64');
zipStream.push(null);
});
zipStream.push(data, 'base64');
zipStream.push(null);
});
});

it('should not pull folders from file system', function (done) {
driver
.pullFolder(__dirname)
.should.be.rejected
.nodeify(done);
});

it('should not be able to fetch a folder that does not exist', function (done) {
driver
.pullFolder('Library/Rollodex')
.should.eventually.be.rejectedWith(/13/)
.nodeify(done);
.should.eventually.be.rejectedWith(/13/)
.nodeify(done);
});
});
});

0 comments on commit 73362b5

Please sign in to comment.