aboutsummaryrefslogtreecommitdiff
path: root/lldb/packages/Python/lldbsuite/support/temp_file.py
blob: a21e212d279d6d4505d3c00af77cac782cafc825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
See https://llvm.org/LICENSE.txt for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""

import os
import tempfile


class OnDiskTempFile:
    def __init__(self, delete=True):
        self.path = None

    def __enter__(self):
        fd, path = tempfile.mkstemp()
        os.close(fd)
        self.path = path
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if os.path.exists(self.path):
            os.remove(self.path)