Skip to contentSkip to conversation

fill_scrapyard.py: Pass a directory to tempfile.mkstemp()

PATCH New Tom Rini 2 participants 3 messages Oct 19, 2015 – Oct 20, 2015

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 fill_scrapyard.py: Pass a directory to tempfile.mkstemp()

In some cases os.rename() may later fail due to "Cross-device link" issues. The easy way to deal with this is to simply make our temporary file here as well rather than TMPDIR.

Cc Masahiro Yamada <[email protected]>
---
 scripts/fill_scrapyard.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/fill_scrapyard.py +1 -1
index 9a94354..cd630ef 100755
@@ -119,7 +119,7 @@ class TmpFile:
 
     def __init__(self):
         """Constructor - create a temporary file"""
-        fd, self.filename = tempfile.mkstemp()
+        fd, self.filename = tempfile.mkstemp(dir='.')
         self.file = os.fdopen(fd, 'w')
 
     def __del__(self):
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 fill_scrapyard.py: Pass a directory to tempfile.mkstemp()

Hi Tom,

2015-10-19 23:56 GMT+09:00 Tom Rini <[email protected]>:

Quoted 15 lines

In some cases os.rename() may later fail due to "Cross-device link" issues. The easy way to deal with this is to simply make our temporary file here as well rather than TMPDIR.

Cc Masahiro Yamada <[email protected]>
---
 scripts/fill_scrapyard.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/fill_scrapyard.py +0 -0
index 9a94354..cd630ef 100755

scripts/fill_scrapyard.py class TmpFile: · line 125

Quoted 8 lines
scripts/fill_scrapyard.py +1 -1
@@ -119,7 +119,7 @@ class TmpFile:
 
     def __init__(self):
         """Constructor - create a temporary file"""
-        fd, self.filename = tempfile.mkstemp()
+        fd, self.filename = tempfile.mkstemp(dir='.')
         self.file = os.fdopen(fd, 'w')
 
     def __del__(self):

I personally prefer replacing "os.rename(tmpfile.filename, DOC)" with "shutil.move(tmpfile.filename, DOC)".

Signature · 2 lines
Best Regards
Masahiro Yamada
author
#2 lore raw

PATCH 1/1 fill_scrapyard.py: Pass a directory to tempfile.mkstemp()

Quoted 26 lines · Masahiro Yamada

Hi Tom,

2015-10-19 23:56 GMT+09:00 Tom Rini <[email protected]>:

Quoted 22 lines

In some cases os.rename() may later fail due to "Cross-device link" issues. The easy way to deal with this is to simply make our temporary file here as well rather than TMPDIR.

Cc Masahiro Yamada <[email protected]>
---
 scripts/fill_scrapyard.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/fill_scrapyard.py +1 -1
index 9a94354..cd630ef 100755
@@ -119,7 +119,7 @@ class TmpFile:
 
     def __init__(self):
         """Constructor - create a temporary file"""
-        fd, self.filename = tempfile.mkstemp()
+        fd, self.filename = tempfile.mkstemp(dir='.')
         self.file = os.fdopen(fd, 'w')
 
Quoted 6 lines

scripts/fill_scrapyard.py class TmpFile: · line 125

Quoted 1 line
scripts/fill_scrapyard.py +0 -0
     def __del__(self):

I personally prefer replacing "os.rename(tmpfile.filename, DOC)" with "shutil.move(tmpfile.filename, DOC)".

Yeah, I saw that too but wasn't sure if we wanted to depend on that package.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151020/814ad17d/attachment.sig>