Skip to content

Commit

Permalink
Merge pull request #622 from oduwsdl/issue-620
Browse files Browse the repository at this point in the history
Use system supplied temp dir instead of hardcoded /tmp
  • Loading branch information
machawk1 authored Aug 10, 2019
2 parents a9060cb + 62a51a7 commit ae3a5e2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ipwb/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import os
import argparse
import tempfile
import string # For generating a temp file for stdin
import random # For generating a temp file for stdin
from .__init__ import __version__ as ipwbVersion
Expand Down Expand Up @@ -46,7 +47,7 @@ def checkArgs_replay(args):

random.seed()
# Write data to temp file (sub-optimal)
tempFilePath = '/tmp/' + ''.join(random.sample(
tempFilePath = tempfile.gettempdir() + '/' + ''.join(random.sample(
string.ascii_uppercase + string.digits * 6, 12)) + '.cdxj'
with open(tempFilePath, 'w') as f:
f.write(cdxjIn)
Expand Down
3 changes: 2 additions & 1 deletion ipwb/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import surt
import ntpath
import traceback
import tempfile

from io import BytesIO
from warcio.archiveiterator import ArchiveIterator
Expand Down Expand Up @@ -115,7 +116,7 @@ def encrypt(hstr, payload, encryptionKey):


def createIPFSTempPath():
ipfsTempPath = '/tmp/ipfs/'
ipfsTempPath = tempfile.gettempdir() + '/ipfs/'

# Create temp path for ipwb temp files if it does not already exist
if not os.path.exists(ipfsTempPath):
Expand Down
3 changes: 2 additions & 1 deletion ipwb/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import re
import signal
import traceback
import tempfile

from flask import Flask
from flask import Response
Expand Down Expand Up @@ -61,7 +62,7 @@
from flask import send_from_directory
from flask import make_response

UPLOAD_FOLDER = '/tmp'
UPLOAD_FOLDER = tempfile.gettempdir()
ALLOWED_EXTENSIONS = ('.warc', '.warc.gz')

app = Flask(__name__)
Expand Down
3 changes: 2 additions & 1 deletion tests/testUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
import string
import re
import tempfile

from time import sleep

Expand Down Expand Up @@ -56,7 +57,7 @@ def startReplay(warcFilename):
global p
pathOfWARC = os.path.join(os.path.dirname(__file__) +
'/../samples/warcs/' + warcFilename)
tempFilePath = '/tmp/' + ''.join(random.sample(
tempFilePath = tempfile.gettempdir() + '/' + ''.join(random.sample(
string.ascii_uppercase + string.digits * 6, 12)) + '.cdxj'

open(tempFilePath, 'a').close() # Create placeholder file for replay
Expand Down

0 comments on commit ae3a5e2

Please sign in to comment.