Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 868574 - devicemanager.mkDirs does not work on root's children; r…
Browse files Browse the repository at this point in the history
…=mcote
  • Loading branch information
mihneadb committed Jul 3, 2013
1 parent ff38d59 commit 52cd9c8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
14 changes: 7 additions & 7 deletions mozdevice/mozdevice/devicemanager.py
Expand Up @@ -6,6 +6,7 @@
import mozlog
import socket
import os
import posixpath
import re
import struct
import StringIO
Expand Down Expand Up @@ -238,15 +239,14 @@ def mkDirs(self, filename):
WARNING: does not create last part of the path. For example, if asked to
create `/mnt/sdcard/foo/bar/baz`, it will only create `/mnt/sdcard/foo/bar`
"""
dirParts = filename.rsplit('/', 1)
if not self.dirExists(dirParts[0]):
filename = posixpath.normpath(filename)
containing = posixpath.dirname(filename)
if not self.dirExists(containing):
parts = filename.split('/')
name = ""
for part in parts:
if part is parts[-1]:
break
name = "/"
for part in parts[:-1]:
if part != "":
name += '/' + part
name = posixpath.join(name, part)
self.mkDir(name) # mkDir will check previous existence

@abstractmethod
Expand Down
12 changes: 5 additions & 7 deletions mozdevice/mozdevice/devicemanagerSUT.py
Expand Up @@ -368,15 +368,13 @@ def pushDir(self, localDir, remoteDir, retryLimit = None):

existentDirectories = []
for root, dirs, files in os.walk(localDir, followlinks=True):
parts = root.split(localDir)
_, subpath = root.split(localDir)
subpath = subpath.lstrip('/')
remoteRoot = posixpath.join(remoteDir, subpath)
for f in files:
remoteRoot = remoteDir + '/' + parts[1]
if (remoteRoot.endswith('/')):
remoteName = remoteRoot + f
else:
remoteName = remoteRoot + '/' + f
remoteName = posixpath.join(remoteRoot, f)

if (parts[1] == ""):
if subpath == "":
remoteRoot = remoteDir

parent = os.path.dirname(remoteName)
Expand Down
9 changes: 9 additions & 0 deletions mozdevice/tests/sut_mkdir.py
Expand Up @@ -59,6 +59,15 @@ def test_repeated_path_part(self):
d.mkDirs('/mnt/sdcard/foo/foo')
a.wait()

def test_mkdirs_on_root(self):
cmds = [('isdir /', 'TRUE')]
a = MockAgent(self, commands=cmds)
d = mozdevice.DroidSUT('127.0.0.1', port=a.port,
logLevel=mozlog.DEBUG)
d.mkDirs('/foo')

a.wait()


if __name__ == '__main__':
unittest.main()
14 changes: 7 additions & 7 deletions mozdevice/tests/sut_push.py
Expand Up @@ -44,21 +44,21 @@ def test_push_dir(self):
f.write(pushfile)
f.flush()

subTests = [ { 'cmds': [ ("isdir /mnt/sdcard//baz", "TRUE"),
("isdir /mnt/sdcard//baz", "TRUE"),
("push /mnt/sdcard//baz/%s %s\r\n%s" %
subTests = [ { 'cmds': [ ("isdir /mnt/sdcard/baz", "TRUE"),
("isdir /mnt/sdcard/baz", "TRUE"),
("push /mnt/sdcard/baz/%s %s\r\n%s" %
(os.path.basename(f.name), len(pushfile),
pushfile),
expectedFileResponse) ],
'expectException': False },
{ 'cmds': [ ("isdir /mnt/sdcard//baz", "TRUE"),
("isdir /mnt/sdcard//baz", "TRUE"),
("push /mnt/sdcard//baz/%s %s\r\n%s" %
{ 'cmds': [ ("isdir /mnt/sdcard/baz", "TRUE"),
("isdir /mnt/sdcard/baz", "TRUE"),
("push /mnt/sdcard/baz/%s %s\r\n%s" %
(os.path.basename(f.name), len(pushfile),
pushfile),
"BADHASH") ],
'expectException': True },
{ 'cmds': [ ("isdir /mnt/sdcard//baz", "FALSE"),
{ 'cmds': [ ("isdir /mnt/sdcard/baz", "FALSE"),
("isdir /mnt", "FALSE"),
("mkdr /mnt",
"##AGENT-WARNING## Could not create the directory /mnt") ],
Expand Down

0 comments on commit 52cd9c8

Please sign in to comment.