Switch to unified view

a/src/utils/rclutil.cpp b/src/utils/rclutil.cpp
...
...
41
#include "rclutil.h"
41
#include "rclutil.h"
42
#include "pathut.h"
42
#include "pathut.h"
43
#include "wipedir.h"
43
#include "wipedir.h"
44
#include "transcode.h"
44
#include "transcode.h"
45
#include "md5ut.h"
45
#include "md5ut.h"
46
#include "log.h"
46
47
47
using namespace std;
48
using namespace std;
48
49
49
50
50
void map_ss_cp_noshr(const map<string, string> s, map<string, string> *d)
51
void map_ss_cp_noshr(const map<string, string> s, map<string, string> *d)
...
...
279
#endif
280
#endif
280
281
281
    return true;
282
    return true;
282
}
283
}
283
284
285
286
class TempFile::Internal {
287
public:
288
    Internal(const std::string& suffix);
289
    ~Internal();
290
    friend class TempFile;
291
private:
292
    std::string m_filename;
293
    std::string m_reason;
294
    bool m_noremove{false};
295
};
296
297
TempFile::TempFile(const string& suffix)
298
    : m(new Internal(suffix))
299
{
300
}
301
302
TempFile::TempFile()
303
{
304
    m = std::shared_ptr<Internal>();
305
}
306
307
const char *TempFile::filename() const
308
{
309
    return m ? m->m_filename.c_str() : "";
310
}
311
312
const std::string& TempFile::getreason() const
313
{
314
    static string fatal{"fatal error"};
315
    return m ? m->m_reason : fatal;
316
}
317
318
void TempFile::setnoremove(bool onoff)
319
{
320
    if (m)
321
        m->m_noremove = onoff;
322
}
323
324
bool TempFile::ok() const
325
{
326
    return m ? !m->m_filename.empty() : false;
327
}
328
284
TempFileInternal::TempFileInternal(const string& suffix)
329
TempFile::Internal::Internal(const string& suffix)
285
    : m_noremove(false)
286
{
330
{
287
    // Because we need a specific suffix, can't use mkstemp
331
    // Because we need a specific suffix, can't use mkstemp
288
    // well. There is a race condition between name computation and
332
    // well. There is a race condition between name computation and
289
    // file creation. try to make sure that we at least don't shoot
333
    // file creation. try to make sure that we at least don't shoot
290
    // our own selves in the foot. maybe we'll use mkstemps one day.
334
    // our own selves in the foot. maybe we'll use mkstemps one day.
...
...
320
        m_reason = string("Could not open/create") + m_filename;
364
        m_reason = string("Could not open/create") + m_filename;
321
        m_filename.erase();
365
        m_filename.erase();
322
    }
366
    }
323
}
367
}
324
368
325
TempFileInternal::~TempFileInternal()
369
TempFile::Internal::~Internal()
326
{
370
{
327
    if (!m_filename.empty() && !m_noremove) {
371
    if (!m_filename.empty() && !m_noremove) {
328
        unlink(m_filename.c_str());
372
        unlink(m_filename.c_str());
329
    }
373
    }
330
}
374
}
...
...
333
{
377
{
334
    if (!maketmpdir(m_dirname, m_reason)) {
378
    if (!maketmpdir(m_dirname, m_reason)) {
335
        m_dirname.erase();
379
        m_dirname.erase();
336
        return;
380
        return;
337
    }
381
    }
382
    LOGDEB("TempDir::TempDir: -> " << m_dirname << endl);
338
}
383
}
339
384
340
TempDir::~TempDir()
385
TempDir::~TempDir()
341
{
386
{
342
    if (!m_dirname.empty()) {
387
    if (!m_dirname.empty()) {
388
        LOGDEB("TempDir::~TempDir: erasing " << m_dirname << endl);
343
        (void)wipedir(m_dirname, true, true);
389
        (void)wipedir(m_dirname, true, true);
344
        m_dirname.erase();
390
        m_dirname.erase();
345
    }
391
    }
346
}
392
}
347
393