mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 20:29:48 +00:00
Convert some uses of PathV1.h in ArchiveWriter.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184599 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a622a3f450
commit
995017caf9
@ -20,6 +20,7 @@
|
|||||||
#include "llvm/ADT/ilist.h"
|
#include "llvm/ADT/ilist.h"
|
||||||
#include "llvm/ADT/ilist_node.h"
|
#include "llvm/ADT/ilist_node.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Support/TimeValue.h"
|
#include "llvm/Support/TimeValue.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -375,7 +376,7 @@ class Archive {
|
|||||||
/// returns true if writing member failed, \p error set to error message.
|
/// returns true if writing member failed, \p error set to error message.
|
||||||
bool writeMember(
|
bool writeMember(
|
||||||
const ArchiveMember& member, ///< The member to be written
|
const ArchiveMember& member, ///< The member to be written
|
||||||
std::ofstream& ARFile, ///< The file to write member onto
|
raw_fd_ostream& ARFile, ///< The file to write member onto
|
||||||
bool TruncateNames, ///< Should names be truncated to 11 chars?
|
bool TruncateNames, ///< Should names be truncated to 11 chars?
|
||||||
std::string* ErrMessage ///< If non-null, place were error msg is set
|
std::string* ErrMessage ///< If non-null, place were error msg is set
|
||||||
);
|
);
|
||||||
|
@ -160,17 +160,22 @@ bool Archive::addFileBefore(StringRef filePath, iterator where,
|
|||||||
|
|
||||||
mbr->data = 0;
|
mbr->data = 0;
|
||||||
mbr->path = filePath;
|
mbr->path = filePath;
|
||||||
sys::PathWithStatus PWS(filePath);
|
sys::fs::file_status Status;
|
||||||
const sys::FileStatus *FSInfo = PWS.getFileStatus(false, ErrMsg);
|
error_code EC = sys::fs::status(filePath, Status);
|
||||||
if (!FSInfo) {
|
if (EC) {
|
||||||
|
delete mbr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
mbr->User = Status.getUser();
|
||||||
|
mbr->Group = Status.getGroup();
|
||||||
|
mbr->Mode = Status.permissions();
|
||||||
|
mbr->ModTime = Status.getLastModificationTime();
|
||||||
|
// FIXME: On posix this is a second stat.
|
||||||
|
EC = sys::fs::file_size(filePath, mbr->Size);
|
||||||
|
if (EC) {
|
||||||
delete mbr;
|
delete mbr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mbr->User = FSInfo->getUser();
|
|
||||||
mbr->Group = FSInfo->getGroup();
|
|
||||||
mbr->Mode = FSInfo->getMode();
|
|
||||||
mbr->ModTime = FSInfo->getTimestamp();
|
|
||||||
mbr->Size = FSInfo->getSize();
|
|
||||||
|
|
||||||
unsigned flags = 0;
|
unsigned flags = 0;
|
||||||
if (sys::path::filename(filePath).size() > 15)
|
if (sys::path::filename(filePath).size() > 15)
|
||||||
@ -195,12 +200,12 @@ bool Archive::addFileBefore(StringRef filePath, iterator where,
|
|||||||
bool
|
bool
|
||||||
Archive::writeMember(
|
Archive::writeMember(
|
||||||
const ArchiveMember& member,
|
const ArchiveMember& member,
|
||||||
std::ofstream& ARFile,
|
raw_fd_ostream& ARFile,
|
||||||
bool TruncateNames,
|
bool TruncateNames,
|
||||||
std::string* ErrMsg
|
std::string* ErrMsg
|
||||||
) {
|
) {
|
||||||
|
|
||||||
unsigned filepos = ARFile.tellp();
|
uint64_t filepos = ARFile.tell();
|
||||||
filepos -= 8;
|
filepos -= 8;
|
||||||
|
|
||||||
// Get the data and its size either from the
|
// Get the data and its size either from the
|
||||||
@ -239,7 +244,7 @@ Archive::writeMember(
|
|||||||
ARFile.write(data,fSize);
|
ARFile.write(data,fSize);
|
||||||
|
|
||||||
// Make sure the member is an even length
|
// Make sure the member is an even length
|
||||||
if ((ARFile.tellp() & 1) == 1)
|
if ((ARFile.tell() & 1) == 1)
|
||||||
ARFile << ARFILE_PAD;
|
ARFile << ARFILE_PAD;
|
||||||
|
|
||||||
// Close the mapped file if it was opened
|
// Close the mapped file if it was opened
|
||||||
@ -261,25 +266,18 @@ bool Archive::writeToDisk(bool TruncateNames, std::string *ErrMsg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a temporary file to store the archive in
|
// Create a temporary file to store the archive in
|
||||||
sys::Path TmpArchive(archPath);
|
int TmpArchiveFD;
|
||||||
if (TmpArchive.createTemporaryFileOnDisk(ErrMsg))
|
SmallString<128> TmpArchive;
|
||||||
|
error_code EC = sys::fs::unique_file("temp-archive-%%%%%%%.a", TmpArchiveFD,
|
||||||
|
TmpArchive);
|
||||||
|
if (EC)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Make sure the temporary gets removed if we crash
|
// Make sure the temporary gets removed if we crash
|
||||||
sys::RemoveFileOnSignal(TmpArchive.str());
|
sys::RemoveFileOnSignal(TmpArchive);
|
||||||
|
|
||||||
// Create archive file for output.
|
// Create archive file for output.
|
||||||
std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
|
raw_fd_ostream ArchiveFile(TmpArchiveFD, true);
|
||||||
std::ios::binary;
|
|
||||||
std::ofstream ArchiveFile(TmpArchive.c_str(), io_mode);
|
|
||||||
|
|
||||||
// Check for errors opening or creating archive file.
|
|
||||||
if (!ArchiveFile.is_open() || ArchiveFile.bad()) {
|
|
||||||
TmpArchive.eraseFromDisk();
|
|
||||||
if (ErrMsg)
|
|
||||||
*ErrMsg = "Error opening archive file: " + archPath;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write magic string to archive.
|
// Write magic string to archive.
|
||||||
ArchiveFile << ARFILE_MAGIC;
|
ArchiveFile << ARFILE_MAGIC;
|
||||||
@ -288,7 +286,7 @@ bool Archive::writeToDisk(bool TruncateNames, std::string *ErrMsg) {
|
|||||||
// builds the symbol table, symTab.
|
// builds the symbol table, symTab.
|
||||||
for (MembersList::iterator I = begin(), E = end(); I != E; ++I) {
|
for (MembersList::iterator I = begin(), E = end(); I != E; ++I) {
|
||||||
if (writeMember(*I, ArchiveFile, TruncateNames, ErrMsg)) {
|
if (writeMember(*I, ArchiveFile, TruncateNames, ErrMsg)) {
|
||||||
TmpArchive.eraseFromDisk();
|
sys::fs::remove(Twine(TmpArchive));
|
||||||
ArchiveFile.close();
|
ArchiveFile.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -302,8 +300,10 @@ bool Archive::writeToDisk(bool TruncateNames, std::string *ErrMsg) {
|
|||||||
// this because we cannot replace an open file on Windows.
|
// this because we cannot replace an open file on Windows.
|
||||||
cleanUpMemory();
|
cleanUpMemory();
|
||||||
|
|
||||||
if (TmpArchive.renamePathOnDisk(sys::Path(archPath), ErrMsg))
|
if (sys::fs::rename(Twine(TmpArchive), archPath)) {
|
||||||
|
*ErrMsg = EC.message();
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Set correct read and write permissions after temporary file is moved
|
// Set correct read and write permissions after temporary file is moved
|
||||||
// to final destination path.
|
// to final destination path.
|
||||||
|
Loading…
Reference in New Issue
Block a user