Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apps/app-frontend/src/composables/useJavaTest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ref } from 'vue'

import { trackEvent } from '@/helpers/analytics'
import { test_jre } from '@/helpers/jre.js'
import { get_jre, test_jre } from '@/helpers/jre.js'

export default function useJavaTest() {
const testingJava = ref(false)
const javaTestResult = ref<boolean | null>(null)
let testDebounceTimer: ReturnType<typeof setTimeout> | null = null

async function runJavaTest(path: string, version: number, track = true) {
async function runJavaTest(path: string, version: number | null, track = true) {
if (testDebounceTimer) {
clearTimeout(testDebounceTimer)
testDebounceTimer = null
Expand All @@ -19,7 +19,8 @@ export default function useJavaTest() {
}
testingJava.value = true
try {
javaTestResult.value = await test_jre(path, version)
javaTestResult.value =
version === null ? !!(await get_jre(path)) : await test_jre(path, version)
} catch {
javaTestResult.value = false
}
Expand All @@ -30,7 +31,7 @@ export default function useJavaTest() {
}
}

function testJavaInstallationDebounced(path: string, version: number, delay = 600) {
function testJavaInstallationDebounced(path: string, version: number | null, delay = 600) {
if (testDebounceTimer) clearTimeout(testDebounceTimer)
if (!path) {
javaTestResult.value = null
Expand All @@ -39,7 +40,7 @@ export default function useJavaTest() {
testDebounceTimer = setTimeout(() => runJavaTest(path, version, false), delay)
}

async function testJavaInstallation(path: string, version: number, track = false) {
async function testJavaInstallation(path: string, version: number | null, track = false) {
await runJavaTest(path, version, track)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ let hasInitialized = false
watch(
javaTestPath,
(newPath) => {
if (newPath && optimalJava?.parsed_version) {
if (newPath) {
if (!hasInitialized) {
testJavaInstallation(newPath, optimalJava?.parsed_version, false)
testJavaInstallation(newPath, null, false)
hasInitialized = true
} else {
testJavaInstallationDebounced(newPath, optimalJava?.parsed_version)
testJavaInstallationDebounced(newPath, null)
}
}
},
{ immediate: true },
)

const javaDetectionModal = ref<{ show: (version: number, current: object) => void } | null>(null)
const javaDetectionModal = ref<{ show: (version: number | null, current: object) => void } | null>(
null,
)

async function handleBrowseJava() {
const result = await open({ multiple: false })
Expand All @@ -84,7 +86,7 @@ async function handleBrowseJava() {
}

function handleDetectJava() {
javaDetectionModal.value?.show(optimalJava?.parsed_version, { path: javaPath.value })
javaDetectionModal.value?.show(null, { path: javaPath.value })
}

const overrideJavaArgs = ref((instance.value.extra_launch_args?.length ?? 0) > 0)
Expand Down Expand Up @@ -262,9 +264,6 @@ const messages = defineMessages({
<CoffeeIcon />
</div>
<div class="flex flex-col gap-2 flex-1 min-w-0">
<span class="font-semibold leading-none mt-2"
>Java {{ optimalJava?.parsed_version }}</span
>
<div class="flex gap-2 items-center">
<Input
:model-value="activePath"
Expand Down Expand Up @@ -306,7 +305,7 @@ const messages = defineMessages({
: undefined,
}"
class="!text-[var(--legacy-button-color,var(--color-base))] [&>svg]:!text-[var(--legacy-button-color,var(--color-primary))]"
@click="testJavaInstallation(activePath, optimalJava?.parsed_version, true)"
@click="testJavaInstallation(activePath, null, true)"
@mouseenter="hoveringTest = true"
@mouseleave="hoveringTest = false"
>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 45 additions & 3 deletions packages/app-lib/src/install/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct SharedInstanceUpdateRollback {
entries: Vec<ContentEntry>,
#[serde(default)]
bindings: Vec<crate::state::content_store::InstanceFileStorage>,
#[serde(default)]
missing_file_ids: std::collections::HashSet<String>,
#[serde(default)]
copied_file_ids: std::collections::HashSet<String>,
}

pub(super) async fn prepare_instance_update_backup(
Expand Down Expand Up @@ -60,7 +64,7 @@ pub(super) async fn prepare_instance_update_backup(
state,
)
.await?;
let files = content_rows::get_instance_files(
let mut files = content_rows::get_instance_files(
&metadata.instance.id,
&state.pool,
)
Expand All @@ -75,9 +79,11 @@ pub(super) async fn prepare_instance_update_backup(
&metadata.instance.id,
)
.await?;
let mut missing_file_ids = std::collections::HashSet::new();
let mut copied_file_ids = std::collections::HashSet::new();
for binding in &bindings {
let file = files
.iter()
.iter_mut()
.find(|file| file.id == binding.file_id)
.ok_or_else(|| {
crate::state::content_store::input(
Expand All @@ -86,20 +92,28 @@ pub(super) async fn prepare_instance_update_backup(
})?;
let file_status = state.content_store
.check_instance_file(&metadata.instance, file, binding).await?;
file.missing = file_status == crate::state::content_store::InstanceFileStatus::Missing;
if file.missing {
missing_file_ids.insert(file.id.clone());
continue;
}
let content = state.content_store.file_content(file).await?;
if file_status != crate::state::content_store::InstanceFileStatus::Healthy
|| !matches!(content, crate::state::content_store::FileContent::Stored { .. })
{
return Err(crate::state::content_store::input(format!(
"Restore or repair {} before updating this instance; its current content cannot be backed up safely",
file.relative_path,
)));
}
if !matches!(content, crate::state::content_store::FileContent::Stored { .. }) {
copied_file_ids.insert(file.id.clone());
}
}
let skipped = files
.iter()
.filter(|file| {
bindings.iter().any(|binding| binding.file_id == file.id)
&& !copied_file_ids.contains(&file.id)
})
.map(crate::state::content_store::content_file_path)
.collect();
Expand All @@ -111,6 +125,8 @@ pub(super) async fn prepare_instance_update_backup(
files,
entries,
bindings,
missing_file_ids,
copied_file_ids,
};
let instance_path = state
.directories
Expand Down Expand Up @@ -247,6 +263,30 @@ async fn restore_instance_update(
));
}
for binding in &snapshot.bindings {
if snapshot.missing_file_ids.contains(&binding.file_id) {
continue;
}
if snapshot.copied_file_ids.contains(&binding.file_id) {
let file = snapshot
.files
.iter()
.find(|file| file.id == binding.file_id)
.ok_or_else(|| {
crate::state::content_store::input(
"Backup content reference has no file record",
)
})?;
let path = backup_path
.join(crate::state::content_store::content_file_path(file));
if crate::state::content_store::hash_file(&path).await?.sha512
!= binding.blob_sha512
{
return Err(crate::state::content_store::input(
"The instance backup contains changed content",
));
}
continue;
}
if state
.content_store
.lookup(Some(&binding.blob_sha512), None)
Expand Down Expand Up @@ -282,6 +322,8 @@ async fn restore_instance_update(
&rollback.instance.instance,
&snapshot.files,
&snapshot.bindings,
&snapshot.missing_file_ids,
&snapshot.copied_file_ids,
)
.await?;

Expand Down
8 changes: 4 additions & 4 deletions packages/app-lib/src/install/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub async fn get(
instance_id,
kind AS \"kind!: String\",
status AS \"status!: String\",
state AS \"state!: String\",
json(state) AS \"state!: String\",
created AS \"created!: i64\",
modified AS \"modified!: i64\",
finished,
Expand Down Expand Up @@ -153,7 +153,7 @@ pub async fn list(
instance_id,
kind AS \"kind!: String\",
status AS \"status!: String\",
state AS \"state!: String\",
json(state) AS \"state!: String\",
created AS \"created!: i64\",
modified AS \"modified!: i64\",
finished,
Expand All @@ -174,7 +174,7 @@ pub async fn list(
instance_id,
kind AS \"kind!: String\",
status AS \"status!: String\",
state AS \"state!: String\",
json(state) AS \"state!: String\",
created AS \"created!: i64\",
modified AS \"modified!: i64\",
finished,
Expand Down Expand Up @@ -202,7 +202,7 @@ pub async fn list_interrupted_candidates(
instance_id,
kind AS \"kind!: String\",
status AS \"status!: String\",
state AS \"state!: String\",
json(state) AS \"state!: String\",
created AS \"created!: i64\",
modified AS \"modified!: i64\",
finished,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ impl ContentStore {
instance: &Instance,
files: &[InstanceFile],
bindings: &[InstanceFileStorage],
missing_file_ids: &std::collections::HashSet<String>,
copied_file_ids: &std::collections::HashSet<String>,
) -> crate::Result<()> {
let files: HashMap<_, _> =
files.iter().map(|file| (file.id.as_str(), file)).collect();
Expand All @@ -131,6 +133,22 @@ impl ContentStore {
files.get(binding.file_id.as_str()).ok_or_else(|| {
input("Rollback content reference has no file record")
})?;
if missing_file_ids.contains(&binding.file_id) {
restored.push((
&binding.file_id,
&binding.blob_sha512,
binding.storage_kind,
));
continue;
}
if copied_file_ids.contains(&binding.file_id) {
restored.push((
&binding.file_id,
&binding.blob_sha512,
FileStorageKind::Copy,
));
continue;
}
let stored_file = self
.lookup(Some(&binding.blob_sha512), Some(file.size))
.await?
Expand Down
Loading
Loading