Skip to content

Commit 199d438

Browse files
authored
Fix single component paths handling in disk space usage check (#6)
1 parent 3dbb0fb commit 199d438

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: lld/ELF/Writer.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -2800,6 +2800,15 @@ template <class ELFT> void Writer<ELFT>::writeHeader() {
28002800
sec->writeHeaderTo<ELFT>(++sHdrs);
28012801
}
28022802

2803+
static StringRef parentPathOrDot(StringRef path) {
2804+
auto parent_path = sys::path::parent_path(path);
2805+
if (parent_path.empty() && !path.empty() && !sys::path::is_absolute(path)) {
2806+
return ".";
2807+
} else {
2808+
return parent_path;
2809+
}
2810+
}
2811+
28032812
// Open a result file.
28042813
template <class ELFT> void Writer<ELFT>::openFile() {
28052814
uint64_t maxSize = config->is64 ? INT64_MAX : UINT32_MAX;
@@ -2825,7 +2834,7 @@ template <class ELFT> void Writer<ELFT>::openFile() {
28252834
// In case there's no space left on the device
28262835
// it will error with SIGBUS, which is confusing
28272836
// for users
2828-
auto ErrOrSpaceInfo = sys::fs::disk_space(sys::path::parent_path(config->outputFile));
2837+
auto ErrOrSpaceInfo = sys::fs::disk_space(parentPathOrDot(config->outputFile));
28292838
if (!ErrOrSpaceInfo)
28302839
error("Can't get remaining size on disk");
28312840
if (ErrOrSpaceInfo.get().free < fileSize)

0 commit comments

Comments
 (0)