Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Data5tream committed Oct 26, 2023
0 parents commit dd38431
Show file tree
Hide file tree
Showing 10 changed files with 776 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/target
8 changes: 8 additions & 0 deletions .idea/.gitignore

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

11 changes: 11 additions & 0 deletions .idea/file_checker.iml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

7 changes: 7 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
@@ -0,0 +1,8 @@
[package]
name = "file_checker"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions README.md
@@ -0,0 +1,8 @@
# Jetbrains Lock Checker

When shutting down a Linux machine without exiting a Jetbrains editor correctly, residual `.lock` files can prevent the
editor from starting again *(See this [StackOverflow post](https://stackoverflow.com/questions/77003028/error-while-opening-intellij-idea-due-to-an-already-running-process))*.

This program deletes those `.lock` files.

*You should not need this. Just shutdown your editors correctly*
45 changes: 45 additions & 0 deletions src/main.rs
@@ -0,0 +1,45 @@
use std::path::Path;

use std::process::exit;
use std::{env, fs};

fn main() {
// get home dir from $HOME env variable and construct config folder string
let home_key = "HOME";
let home_dir = env::var(home_key).expect("$HOME variable not set");
let config_dir = format!("{}/.config/JetBrains", home_dir);

// make sure the path exists
if !Path::new(&config_dir).exists() {
println!("JetBrains config folder doesn't exist");
exit(1);
}

// get paths in config folder
let paths = fs::read_dir(&config_dir).unwrap();

let mut got_error = false;

for path in paths {
let p = path.unwrap();

if p.file_type().unwrap().is_dir() {
let lock_path = format!("{}/.lock", p.path().display());

// try to delete the lock file, if an error occurs that's not the file not found error, print it out
match fs::remove_file(&lock_path) {
Ok(_) => {}
Err(e) => {
if e.kind().to_string() != "entity not found" {
println!("{}", e);
got_error = true;
}
}
};
}
}

if got_error {
exit(1)
}
}

0 comments on commit dd38431

Please sign in to comment.