Skip to content

Commit e3c0054

Browse files
Forestrykspoechsel
authored andcommitted
Fix single component paths handling in disk space usage check (#6)
1 parent a5a799e commit e3c0054

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lld/ELF/Writer.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,15 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
27442744
sec->writeHeaderTo<ELFT>(++sHdrs);
27452745
}
27462746

2747+
static StringRef parentPathOrDot(StringRef path) {
2748+
auto parent_path = sys::path::parent_path(path);
2749+
if (parent_path.empty() && !path.empty() && !sys::path::is_absolute(path)) {
2750+
return ".";
2751+
} else {
2752+
return parent_path;
2753+
}
2754+
}
2755+
27472756
// Open a result file.
27482757
template <class ELFT> void Writer<ELFT>::openFile() {
27492758
uint64_t maxSize = config->is64 ? INT64_MAX : UINT32_MAX;
@@ -2769,7 +2778,7 @@ template <class ELFT> void Writer<ELFT>::openFile() {
27692778
// In case there's no space left on the device
27702779
// it will error with SIGBUS, which is confusing
27712780
// for users
2772-
auto ErrOrSpaceInfo = sys::fs::disk_space(sys::path::parent_path(config->outputFile));
2781+
auto ErrOrSpaceInfo = sys::fs::disk_space(parentPathOrDot(config->outputFile));
27732782
if (!ErrOrSpaceInfo)
27742783
error("Can't get remaining size on disk");
27752784
if (ErrOrSpaceInfo.get().free < fileSize)

0 commit comments

Comments
 (0)