mirror of
https://github.com/NixOS/nix
synced 2025-06-27 21:01:16 +02:00
Merge pull request #12167 from RossComputerGuy/fix/unsupported-type-docker
nix flake: clarify error message when file is an unknown type
This commit is contained in:
commit
84f116e3cf
7 changed files with 59 additions and 13 deletions
|
@ -291,7 +291,11 @@ json listNar(ref<SourceAccessor> accessor, const CanonPath & path, bool recurse)
|
||||||
obj["type"] = "symlink";
|
obj["type"] = "symlink";
|
||||||
obj["target"] = accessor->readLink(path);
|
obj["target"] = accessor->readLink(path);
|
||||||
break;
|
break;
|
||||||
case SourceAccessor::Type::tMisc:
|
case SourceAccessor::Type::tBlock:
|
||||||
|
case SourceAccessor::Type::tChar:
|
||||||
|
case SourceAccessor::Type::tSocket:
|
||||||
|
case SourceAccessor::Type::tFifo:
|
||||||
|
case SourceAccessor::Type::tUnknown:
|
||||||
assert(false); // cannot happen for NARs
|
assert(false); // cannot happen for NARs
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
|
|
@ -49,11 +49,13 @@ void copyRecursive(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SourceAccessor::tMisc:
|
case SourceAccessor::tChar:
|
||||||
throw Error("file '%1%' has an unsupported type", from);
|
case SourceAccessor::tBlock:
|
||||||
|
case SourceAccessor::tSocket:
|
||||||
|
case SourceAccessor::tFifo:
|
||||||
|
case SourceAccessor::tUnknown:
|
||||||
default:
|
default:
|
||||||
unreachable();
|
throw Error("file '%1%' has an unsupported type of %2%", from, stat.typeString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,7 +200,11 @@ std::optional<Mode> convertMode(SourceAccessor::Type type)
|
||||||
case SourceAccessor::tSymlink: return Mode::Symlink;
|
case SourceAccessor::tSymlink: return Mode::Symlink;
|
||||||
case SourceAccessor::tRegular: return Mode::Regular;
|
case SourceAccessor::tRegular: return Mode::Regular;
|
||||||
case SourceAccessor::tDirectory: return Mode::Directory;
|
case SourceAccessor::tDirectory: return Mode::Directory;
|
||||||
case SourceAccessor::tMisc: return std::nullopt;
|
case SourceAccessor::tChar:
|
||||||
|
case SourceAccessor::tBlock:
|
||||||
|
case SourceAccessor::tSocket:
|
||||||
|
case SourceAccessor::tFifo: return std::nullopt;
|
||||||
|
case SourceAccessor::tUnknown:
|
||||||
default: unreachable();
|
default: unreachable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,9 +318,13 @@ Mode dump(
|
||||||
return Mode::Symlink;
|
return Mode::Symlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SourceAccessor::tMisc:
|
case SourceAccessor::tChar:
|
||||||
|
case SourceAccessor::tBlock:
|
||||||
|
case SourceAccessor::tSocket:
|
||||||
|
case SourceAccessor::tFifo:
|
||||||
|
case SourceAccessor::tUnknown:
|
||||||
default:
|
default:
|
||||||
throw Error("file '%1%' has an unsupported type", path);
|
throw Error("file '%1%' has an unsupported type of %2%", path, st.typeString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,11 @@ std::optional<SourceAccessor::Stat> PosixSourceAccessor::maybeLstat(const CanonP
|
||||||
S_ISREG(st->st_mode) ? tRegular :
|
S_ISREG(st->st_mode) ? tRegular :
|
||||||
S_ISDIR(st->st_mode) ? tDirectory :
|
S_ISDIR(st->st_mode) ? tDirectory :
|
||||||
S_ISLNK(st->st_mode) ? tSymlink :
|
S_ISLNK(st->st_mode) ? tSymlink :
|
||||||
tMisc,
|
S_ISCHR(st->st_mode) ? tChar :
|
||||||
|
S_ISBLK(st->st_mode) ? tBlock :
|
||||||
|
S_ISSOCK(st->st_mode) ? tSocket :
|
||||||
|
S_ISFIFO(st->st_mode) ? tFifo :
|
||||||
|
tUnknown,
|
||||||
.fileSize = S_ISREG(st->st_mode) ? std::optional<uint64_t>(st->st_size) : std::nullopt,
|
.fileSize = S_ISREG(st->st_mode) ? std::optional<uint64_t>(st->st_size) : std::nullopt,
|
||||||
.isExecutable = S_ISREG(st->st_mode) && st->st_mode & S_IXUSR,
|
.isExecutable = S_ISREG(st->st_mode) && st->st_mode & S_IXUSR,
|
||||||
};
|
};
|
||||||
|
@ -156,7 +160,11 @@ SourceAccessor::DirEntries PosixSourceAccessor::readDirectory(const CanonPath &
|
||||||
case std::filesystem::file_type::regular: return Type::tRegular; break;
|
case std::filesystem::file_type::regular: return Type::tRegular; break;
|
||||||
case std::filesystem::file_type::symlink: return Type::tSymlink; break;
|
case std::filesystem::file_type::symlink: return Type::tSymlink; break;
|
||||||
case std::filesystem::file_type::directory: return Type::tDirectory; break;
|
case std::filesystem::file_type::directory: return Type::tDirectory; break;
|
||||||
default: return tMisc;
|
case std::filesystem::file_type::character: return Type::tChar; break;
|
||||||
|
case std::filesystem::file_type::block: return Type::tBlock; break;
|
||||||
|
case std::filesystem::file_type::fifo: return Type::tFifo; break;
|
||||||
|
case std::filesystem::file_type::socket: return Type::tSocket; break;
|
||||||
|
default: return tUnknown;
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
}();
|
}();
|
||||||
|
|
|
@ -5,6 +5,26 @@ namespace nix {
|
||||||
|
|
||||||
static std::atomic<size_t> nextNumber{0};
|
static std::atomic<size_t> nextNumber{0};
|
||||||
|
|
||||||
|
bool SourceAccessor::Stat::isNotNARSerialisable()
|
||||||
|
{
|
||||||
|
return this->type != tRegular && this->type != tSymlink && this->type != tDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SourceAccessor::Stat::typeString() {
|
||||||
|
switch (this->type) {
|
||||||
|
case tRegular: return "regular";
|
||||||
|
case tSymlink: return "symlink";
|
||||||
|
case tDirectory: return "directory";
|
||||||
|
case tChar: return "character device";
|
||||||
|
case tBlock: return "block device";
|
||||||
|
case tSocket: return "socket";
|
||||||
|
case tFifo: return "fifo";
|
||||||
|
case tUnknown:
|
||||||
|
default: return "unknown";
|
||||||
|
}
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
SourceAccessor::SourceAccessor()
|
SourceAccessor::SourceAccessor()
|
||||||
: number(++nextNumber)
|
: number(++nextNumber)
|
||||||
, displayPrefix{"«unknown»"}
|
, displayPrefix{"«unknown»"}
|
||||||
|
|
|
@ -88,12 +88,13 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
|
||||||
|
|
||||||
Unlike `DT_UNKNOWN`, this must not be used for deferring the lookup of types.
|
Unlike `DT_UNKNOWN`, this must not be used for deferring the lookup of types.
|
||||||
*/
|
*/
|
||||||
tMisc
|
tChar, tBlock, tSocket, tFifo,
|
||||||
|
tUnknown
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Stat
|
struct Stat
|
||||||
{
|
{
|
||||||
Type type = tMisc;
|
Type type = tUnknown;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For regular files only: the size of the file. Not all
|
* For regular files only: the size of the file. Not all
|
||||||
|
@ -112,6 +113,9 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
|
||||||
* file in the NAR. Only returned by NAR accessors.
|
* file in the NAR. Only returned by NAR accessors.
|
||||||
*/
|
*/
|
||||||
std::optional<uint64_t> narOffset;
|
std::optional<uint64_t> narOffset;
|
||||||
|
|
||||||
|
bool isNotNARSerialisable();
|
||||||
|
std::string typeString();
|
||||||
};
|
};
|
||||||
|
|
||||||
Stat lstat(const CanonPath & path);
|
Stat lstat(const CanonPath & path);
|
||||||
|
|
|
@ -941,7 +941,7 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
|
||||||
createSymlink(target, os_string_to_string(PathViewNG { to2 }));
|
createSymlink(target, os_string_to_string(PathViewNG { to2 }));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw Error("file '%s' has unsupported type", from2);
|
throw Error("path '%s' needs to be a symlink, file, or directory but instead is a %s", from2, st.typeString());
|
||||||
changedFiles.push_back(to2);
|
changedFiles.push_back(to2);
|
||||||
notice("wrote: %s", to2);
|
notice("wrote: %s", to2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue