io/linux/ProcPath: new library
This commit is contained in:
parent
7c0b561a16
commit
ccbacb369b
|
@ -4,13 +4,13 @@
|
||||||
#include "FileOutputStream.hxx"
|
#include "FileOutputStream.hxx"
|
||||||
#include "lib/fmt/PathFormatter.hxx"
|
#include "lib/fmt/PathFormatter.hxx"
|
||||||
#include "lib/fmt/SystemError.hxx"
|
#include "lib/fmt/SystemError.hxx"
|
||||||
#include "lib/fmt/ToBuffer.hxx"
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
#include "io/linux/ProcPath.hxx"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -281,8 +281,7 @@ try {
|
||||||
unlinkat(directory_fd.Get(), GetPath().c_str(), 0);
|
unlinkat(directory_fd.Get(), GetPath().c_str(), 0);
|
||||||
|
|
||||||
/* hard-link the temporary file to the final path */
|
/* hard-link the temporary file to the final path */
|
||||||
if (linkat(-1,
|
if (linkat(-1, ProcFdPath(fd),
|
||||||
FmtBuffer<64>("/proc/self/fd/{}", fd.Get()),
|
|
||||||
directory_fd.Get(), path.c_str(),
|
directory_fd.Get(), path.c_str(),
|
||||||
AT_SYMLINK_FOLLOW) < 0)
|
AT_SYMLINK_FOLLOW) < 0)
|
||||||
throw FmtErrno("Failed to commit {}", path);
|
throw FmtErrno("Failed to commit {}", path);
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
// Copyright CM4all GmbH
|
||||||
|
// author: Max Kellermann <mk@cm4all.com>
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "lib/fmt/ToBuffer.hxx"
|
||||||
|
#include "io/FileDescriptor.hxx"
|
||||||
|
#include "util/StringBuffer.hxx"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the path to the "/proc/self/fd/" magic link of the given file
|
||||||
|
* descriptor.
|
||||||
|
*/
|
||||||
|
[[gnu::const]]
|
||||||
|
inline StringBuffer<32>
|
||||||
|
ProcFdPath(FileDescriptor fd) noexcept
|
||||||
|
{
|
||||||
|
return FmtBuffer<32>("/proc/self/fd/{}", fd.Get());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the path to the "/proc/self/fdinfo/" file of the given file
|
||||||
|
* descriptor.
|
||||||
|
*/
|
||||||
|
[[gnu::const]]
|
||||||
|
inline StringBuffer<32>
|
||||||
|
ProcFdinfoPath(FileDescriptor fd) noexcept
|
||||||
|
{
|
||||||
|
return FmtBuffer<32>("/proc/self/fdinfo/{}", fd.Get());
|
||||||
|
}
|
Loading…
Reference in New Issue