mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-09-27 13:40:38 +00:00
fix: handle filesystem errors during lora and upscaler cache scan (#2064)
This commit is contained in:
parent
168f7b88b9
commit
9947eebec8
@ -40,4 +40,6 @@ RUN printf '#!/bin/sh\nexec /sd.cpp/bin/sd-cli "$@"\n' > /sd-cli && \
|
|||||||
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
||||||
chmod +x /sd-cli /sd-server
|
chmod +x /sd-cli /sd-server
|
||||||
|
|
||||||
|
WORKDIR /sd.cpp
|
||||||
|
|
||||||
ENTRYPOINT [ "/sd-cli" ]
|
ENTRYPOINT [ "/sd-cli" ]
|
||||||
|
|||||||
@ -57,4 +57,6 @@ RUN printf '#!/bin/sh\nexec /sd.cpp/bin/sd-cli "$@"\n' > /sd-cli && \
|
|||||||
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
||||||
chmod +x /sd-cli /sd-server
|
chmod +x /sd-cli /sd-server
|
||||||
|
|
||||||
|
WORKDIR /sd.cpp
|
||||||
|
|
||||||
ENTRYPOINT [ "/sd-cli" ]
|
ENTRYPOINT [ "/sd-cli" ]
|
||||||
|
|||||||
@ -42,4 +42,6 @@ RUN printf '#!/bin/sh\nexec /sd.cpp/bin/sd-cli "$@"\n' > /sd-cli && \
|
|||||||
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
||||||
chmod +x /sd-cli /sd-server
|
chmod +x /sd-cli /sd-server
|
||||||
|
|
||||||
|
WORKDIR /sd.cpp
|
||||||
|
|
||||||
ENTRYPOINT [ "/sd-cli" ]
|
ENTRYPOINT [ "/sd-cli" ]
|
||||||
|
|||||||
@ -29,4 +29,6 @@ FROM intel/oneapi-basekit:${SYCL_VERSION}-devel-ubuntu24.04 AS runtime
|
|||||||
COPY --from=build /sd.cpp/build/bin/sd-cli /sd-cli
|
COPY --from=build /sd.cpp/build/bin/sd-cli /sd-cli
|
||||||
COPY --from=build /sd.cpp/build/bin/sd-server /sd-server
|
COPY --from=build /sd.cpp/build/bin/sd-server /sd-server
|
||||||
|
|
||||||
|
WORKDIR /sd.cpp
|
||||||
|
|
||||||
ENTRYPOINT [ "/sd-cli" ]
|
ENTRYPOINT [ "/sd-cli" ]
|
||||||
@ -41,4 +41,6 @@ RUN printf '#!/bin/sh\nexec /sd.cpp/bin/sd-cli "$@"\n' > /sd-cli && \
|
|||||||
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
||||||
chmod +x /sd-cli /sd-server
|
chmod +x /sd-cli /sd-server
|
||||||
|
|
||||||
|
WORKDIR /sd.cpp
|
||||||
|
|
||||||
ENTRYPOINT [ "/sd-cli" ]
|
ENTRYPOINT [ "/sd-cli" ]
|
||||||
|
|||||||
@ -255,13 +255,24 @@ void refresh_lora_cache(ServerRuntime& rt) {
|
|||||||
std::vector<LoraEntry> new_cache;
|
std::vector<LoraEntry> new_cache;
|
||||||
|
|
||||||
fs::path lora_dir = rt.ctx_params->lora_model_dir;
|
fs::path lora_dir = rt.ctx_params->lora_model_dir;
|
||||||
if (fs::exists(lora_dir) && fs::is_directory(lora_dir)) {
|
std::error_code ec;
|
||||||
for (auto& entry : fs::recursive_directory_iterator(lora_dir, fs::directory_options::skip_permission_denied)) {
|
if (fs::exists(lora_dir, ec) && !ec && fs::is_directory(lora_dir, ec) && !ec) {
|
||||||
if (!entry.is_regular_file()) {
|
try {
|
||||||
|
auto it = fs::recursive_directory_iterator(
|
||||||
|
lora_dir,
|
||||||
|
fs::directory_options::skip_permission_denied,
|
||||||
|
ec);
|
||||||
|
auto end = fs::recursive_directory_iterator();
|
||||||
|
while (!ec && it != end) {
|
||||||
|
std::error_code entry_ec;
|
||||||
|
bool is_reg = it->is_regular_file(entry_ec);
|
||||||
|
if (entry_ec || !is_reg) {
|
||||||
|
it.increment(ec);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const fs::path& p = entry.path();
|
const fs::path& p = it->path();
|
||||||
if (!is_supported_model_ext(p)) {
|
if (!is_supported_model_ext(p)) {
|
||||||
|
it.increment(ec);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +284,17 @@ void refresh_lora_cache(ServerRuntime& rt) {
|
|||||||
lora_entry.path = rel;
|
lora_entry.path = rel;
|
||||||
|
|
||||||
new_cache.push_back(std::move(lora_entry));
|
new_cache.push_back(std::move(lora_entry));
|
||||||
|
it.increment(ec);
|
||||||
}
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
LOG_WARN("error while scanning lora directory '%s': %s", lora_dir.string().c_str(), e.what());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ec) {
|
||||||
|
LOG_WARN("error while scanning lora directory '%s': %s", lora_dir.string().c_str(), ec.message().c_str());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(new_cache.begin(), new_cache.end(), [](const LoraEntry& a, const LoraEntry& b) {
|
std::sort(new_cache.begin(), new_cache.end(), [](const LoraEntry& a, const LoraEntry& b) {
|
||||||
@ -302,27 +323,48 @@ void refresh_upscaler_cache(ServerRuntime& rt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fs::path upscaler_dir = rt.ctx_params->hires_upscalers_dir;
|
fs::path upscaler_dir = rt.ctx_params->hires_upscalers_dir;
|
||||||
if (fs::exists(upscaler_dir) && fs::is_directory(upscaler_dir)) {
|
std::error_code ec;
|
||||||
for (auto& entry : fs::directory_iterator(upscaler_dir)) {
|
if (fs::exists(upscaler_dir, ec) && !ec && fs::is_directory(upscaler_dir, ec) && !ec) {
|
||||||
if (!entry.is_regular_file()) {
|
try {
|
||||||
|
auto it = fs::directory_iterator(
|
||||||
|
upscaler_dir,
|
||||||
|
fs::directory_options::skip_permission_denied,
|
||||||
|
ec);
|
||||||
|
auto end = fs::directory_iterator();
|
||||||
|
while (!ec && it != end) {
|
||||||
|
std::error_code entry_ec;
|
||||||
|
bool is_reg = it->is_regular_file(entry_ec);
|
||||||
|
if (entry_ec || !is_reg) {
|
||||||
|
it.increment(ec);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const fs::path& p = entry.path();
|
const fs::path& p = it->path();
|
||||||
if (!is_supported_model_ext(p)) {
|
if (!is_supported_model_ext(p)) {
|
||||||
|
it.increment(ec);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpscalerEntry upscaler_entry;
|
UpscalerEntry upscaler_entry;
|
||||||
upscaler_entry.name = p.stem().u8string();
|
upscaler_entry.name = p.stem().u8string();
|
||||||
upscaler_entry.fullpath = fs::absolute(p).lexically_normal().u8string();
|
std::error_code abs_ec;
|
||||||
|
fs::path abs_path = fs::absolute(p, abs_ec);
|
||||||
|
upscaler_entry.fullpath = (abs_ec ? p : abs_path.lexically_normal()).u8string();
|
||||||
upscaler_entry.model_name = "ESRGAN_4x";
|
upscaler_entry.model_name = "ESRGAN_4x";
|
||||||
upscaler_entry.path = p.filename().u8string();
|
upscaler_entry.path = p.filename().u8string();
|
||||||
upscaler_entry.file_size = entry.file_size();
|
|
||||||
upscaler_entry.last_modified = entry.last_write_time();
|
std::error_code size_ec;
|
||||||
|
upscaler_entry.file_size = it->file_size(size_ec);
|
||||||
|
if (size_ec) {
|
||||||
|
it.increment(ec);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::error_code time_ec;
|
||||||
|
upscaler_entry.last_modified = it->last_write_time(time_ec);
|
||||||
auto previous = std::find_if(previous_cache.begin(), previous_cache.end(), [&](const UpscalerEntry& cached) {
|
auto previous = std::find_if(previous_cache.begin(), previous_cache.end(), [&](const UpscalerEntry& cached) {
|
||||||
return cached.fullpath == upscaler_entry.fullpath &&
|
return cached.fullpath == upscaler_entry.fullpath &&
|
||||||
cached.file_size == upscaler_entry.file_size &&
|
cached.file_size == upscaler_entry.file_size &&
|
||||||
cached.last_modified == upscaler_entry.last_modified;
|
(!time_ec && cached.last_modified == upscaler_entry.last_modified);
|
||||||
});
|
});
|
||||||
upscaler_entry.image_upscale_factor = previous != previous_cache.end()
|
upscaler_entry.image_upscale_factor = previous != previous_cache.end()
|
||||||
? previous->image_upscale_factor
|
? previous->image_upscale_factor
|
||||||
@ -333,7 +375,17 @@ void refresh_upscaler_cache(ServerRuntime& rt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_cache.push_back(std::move(upscaler_entry));
|
new_cache.push_back(std::move(upscaler_entry));
|
||||||
|
it.increment(ec);
|
||||||
}
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
LOG_WARN("error while scanning upscalers directory '%s': %s", upscaler_dir.string().c_str(), e.what());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ec) {
|
||||||
|
LOG_WARN("error while scanning upscalers directory '%s': %s", upscaler_dir.string().c_str(), ec.message().c_str());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(new_cache.begin(), new_cache.end(), [](const UpscalerEntry& a, const UpscalerEntry& b) {
|
std::sort(new_cache.begin(), new_cache.end(), [](const UpscalerEntry& a, const UpscalerEntry& b) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user