1/*
2* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3*
4* Licensed under the Apache License, Version 2.0 (the "License").
5* You may not use this file except in compliance with the License.
6* A copy of the License is located at
7*
8* http://aws.amazon.com/apache2.0
9*
10* or in the "license" file accompanying this file. This file is distributed
11* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12* express or implied. See the License for the specific language governing
13* permissions and limitations under the License.
14*/
15
16#include <aws/core/utils/FileSystemUtils.h>
17
18#include <aws/core/platform/FileSystem.h>
19
20namespace Aws
21{
22 namespace Utils
23 {
24 static Aws::String ComputeTempFileName(const char* prefix, const char* suffix)
25 {
26 Aws::String prefixStr;
27
28 if (prefix)
29 {
30 prefixStr = prefix;
31 }
32
33 Aws::String suffixStr;
34
35 if (suffix)
36 {
37 suffixStr = suffix;
38 }
39
40 return prefixStr + Aws::FileSystem::CreateTempFilePath() + suffixStr;
41 }
42
43 TempFile::TempFile(const char* prefix, const char* suffix, std::ios_base::openmode openFlags) :
44 FStreamWithFileName(ComputeTempFileName(prefix, suffix).c_str(), openFlags)
45 {
46 }
47
48 TempFile::TempFile(const char* prefix, std::ios_base::openmode openFlags) :
49 FStreamWithFileName(ComputeTempFileName(prefix, nullptr).c_str(), openFlags)
50 {
51 }
52
53 TempFile::TempFile(std::ios_base::openmode openFlags) :
54 FStreamWithFileName(ComputeTempFileName(nullptr, nullptr).c_str(), openFlags)
55 {
56 }
57
58
59 TempFile::~TempFile()
60 {
61 Aws::FileSystem::RemoveFileIfExists(m_fileName.c_str());
62 }
63 }
64}