summaryrefslogtreecommitdiff
path: root/elpa/irony-20220110.849/server/src/support/TemporaryFile.cpp
diff options
context:
space:
mode:
authormattkae <mattkae@protonmail.com>2022-06-07 08:23:47 -0400
committermattkae <mattkae@protonmail.com>2022-06-07 08:23:47 -0400
commitbd18a38c2898548a3664a9ddab9f79c84f2caf4a (patch)
tree95b9933376770381bd8859782ae763be81c2d72b /elpa/irony-20220110.849/server/src/support/TemporaryFile.cpp
parentb07628dddf418d4f47b858e6c35fd3520fbaeed2 (diff)
parentef160dea332af4b4fe5e2717b962936c67e5fe9e (diff)
Merge conflict
Diffstat (limited to 'elpa/irony-20220110.849/server/src/support/TemporaryFile.cpp')
-rw-r--r--elpa/irony-20220110.849/server/src/support/TemporaryFile.cpp74
1 files changed, 0 insertions, 74 deletions
diff --git a/elpa/irony-20220110.849/server/src/support/TemporaryFile.cpp b/elpa/irony-20220110.849/server/src/support/TemporaryFile.cpp
deleted file mode 100644
index e7393e1..0000000
--- a/elpa/irony-20220110.849/server/src/support/TemporaryFile.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * \file
- * \author Guillaume Papin <guillaume.papin@epitech.eu>
- *
- * This file is distributed under the GNU General Public License. See
- * COPYING for details.
- */
-
-#include "TemporaryFile.h"
-
-#include <algorithm>
-#include <cstdio>
-#include <cstdlib>
-#include <fstream>
-#include <iostream>
-#include <random>
-
-static std::string getTemporaryFileDirectory() {
- const char *temporaryDirEnvVars[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};
-
- for (const char *envVar : temporaryDirEnvVars) {
- if (const char *dir = std::getenv(envVar))
- return dir;
- }
-
- return "/tmp";
-}
-
-TemporaryFile::TemporaryFile(const std::string &prefix,
- const std::string &suffix)
- : pathOrPattern_(prefix + "-%%%%%%" + suffix) {
-}
-
-TemporaryFile::~TemporaryFile() {
- if (openedFile_) {
- openedFile_.reset();
- std::remove(pathOrPattern_.c_str());
- }
-}
-
-const std::string &TemporaryFile::getPath() {
- if (!openedFile_) {
- openedFile_.reset(new std::fstream);
-
- std::random_device rd;
- std::default_random_engine e(rd());
- std::uniform_int_distribution<int> dist(0, 15);
- std::string pattern = pathOrPattern_;
- std::string tmpDir = getTemporaryFileDirectory() + "/";
- int i = 0;
-
- do {
- // exiting is better than infinite loop
- if (++i > TemporaryFile::MAX_ATTEMPS) {
- std::cerr << "error: couldn't create temporary file, please check your "
- "temporary file directory (" << tmpDir << ")\n";
- exit(EXIT_FAILURE);
- }
-
- // make the filename based on the pattern
- std::transform(pattern.begin(),
- pattern.end(),
- pathOrPattern_.begin(),
- [&e, &dist](char ch) {
- return ch == '%' ? "0123456789abcdef"[dist(e)] : ch;
- });
- // create the file
- openedFile_->open(tmpDir + pathOrPattern_, std::ios_base::out);
- } while (!openedFile_->is_open());
- pathOrPattern_ = tmpDir + pathOrPattern_;
- }
-
- return pathOrPattern_;
-}