From c2f649f6b791828237b23033c19874ae314d386d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Dalleau?=
 <frederic.dalleau@collabora.co.uk>
Date: Mon, 3 Oct 2016 14:02:15 +0000
Subject: [PATCH] bluez/ubt: Use temporary filename in dun and pan tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In dun and pan tests, a file is retrieve from http to verify connection,
it is saved at the location defined in variable path. But path do not
contain a file path. Instead it's a dbus object path in /net/connman
namespace. As such, it is not suitable for using as a filename and any
tentative to open this file will end with an "File Not Found" error.

Instead, create a temporary filename that will be automatically deleted.

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Signed-off-by: Frédéric Dalleau <frederic.dalleau@collabora.co.uk>
Differential Revision: https://phabricator.apertis.org/D4447
---
 bluez/ubt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bluez/ubt b/bluez/ubt
index 30aec180..adced7ed 100644
--- a/bluez/ubt
+++ b/bluez/ubt
@@ -27,6 +27,7 @@ import dbus
 import dbus.service
 import dbus.mainloop.glib
 import sys
+import tempfile
 import time
 import urllib.request
 from optparse import OptionParser
@@ -470,7 +471,7 @@ class PbapDeviceProfileTester(DeviceProfileTester):
                                  "net.connman.Service")
         service.Connect(timeout=60000)
         url = urllib.request.urlopen("http://connman.net")
-        f = open(path, 'w')
+        f = tempfile.TemporaryFile('w')
         f.write(url.read(1000000).decode('utf-8'))
         f.close()
         service.Disconnect(timeout=60000)
-- 
GitLab