aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authordenis <denismaximov98@gmail.com>2021-01-24 18:40:14 +0200
committerdenis <denismaximov98@gmail.com>2021-01-24 18:40:14 +0200
commit454de6c52cf58466c4ea41a21435835bc69faa6c (patch)
tree2f8f78f041a05b9bf2bea8c6247377dbb5aedb02 /src/utils
parentwip: restructing in progress, to prep for server-client (diff)
downloadsl0ppij-454de6c52cf58466c4ea41a21435835bc69faa6c.tar.gz
sl0ppij-454de6c52cf58466c4ea41a21435835bc69faa6c.tar.xz
sl0ppij-454de6c52cf58466c4ea41a21435835bc69faa6c.zip
wip: oops shouldn't forget that
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/consts.rs6
-rw-r--r--src/utils/logging.rs76
-rw-r--r--src/utils/mod.rs3
-rw-r--r--src/utils/shared.rs19
4 files changed, 0 insertions, 104 deletions
diff --git a/src/utils/consts.rs b/src/utils/consts.rs
deleted file mode 100644
index 7a0c9ddf..00000000
--- a/src/utils/consts.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-pub const MOSAIC_TMP_DIR: &str = "/tmp/mosaic";
-pub const MOSAIC_TMP_LOG_DIR: &str = "/tmp/mosaic/mosaic-log";
-pub const MOSAIC_TMP_LOG_FILE: &str = "/tmp/mosaic/mosaic-log/log.txt";
-pub const MOSAIC_IPC_PIPE: &str = "/tmp/mosaic/ipc";
-pub const MOSAIC_ROOT_PLUGIN_DIR: &str = "/usr/share/mosaic/plugins";
-pub const MOSAIC_ROOT_LAYOUT_DIR: &str = "/usr/share/mosaic/layouts";
diff --git a/src/utils/logging.rs b/src/utils/logging.rs
deleted file mode 100644
index 05af455c..00000000
--- a/src/utils/logging.rs
+++ /dev/null
@@ -1,76 +0,0 @@
-use std::{
- fs,
- io::{self, prelude::*},
- os::unix::io::RawFd,
- path::PathBuf,
-};
-
-use crate::utils::consts::{MOSAIC_TMP_LOG_DIR, MOSAIC_TMP_LOG_FILE};
-
-pub fn atomic_create_file(file_name: &str) {
- let _ = fs::OpenOptions::new().create(true).open(file_name);
-}
-
-pub fn atomic_create_dir(dir_name: &str) -> io::Result<()> {
- if let Err(e) = fs::create_dir(dir_name) {
- if e.kind() == std::io::ErrorKind::AlreadyExists {
- Ok(())
- } else {
- Err(e)
- }
- } else {
- Ok(())
- }
-}
-
-pub fn debug_log_to_file(mut message: String) -> io::Result<()> {
- message.push('\n');
- debug_log_to_file_without_newline(message)
-}
-
-pub fn debug_log_to_file_without_newline(message: String) -> io::Result<()> {
- atomic_create_file(MOSAIC_TMP_LOG_FILE);
- let mut file = fs::OpenOptions::new()
- .append(true)
- .create(true)
- .open(MOSAIC_TMP_LOG_FILE)?;
- file.write_all(message.as_bytes())
-}
-
-pub fn _debug_log_to_file_pid_3(message: String, pid: RawFd) -> io::Result<()> {
- if pid == 3 {
- debug_log_to_file(message)
- } else {
- Ok(())
- }
-}
-
-#[allow(dead_code)]
-pub fn delete_log_file() -> io::Result<()> {
- if fs::metadata(MOSAIC_TMP_LOG_FILE).is_ok() {
- fs::remove_file(MOSAIC_TMP_LOG_FILE)
- } else {
- Ok(())
- }
-}
-
-#[allow(dead_code)]
-pub fn delete_log_dir() -> io::Result<()> {
- if fs::metadata(MOSAIC_TMP_LOG_DIR).is_ok() {
- fs::remove_dir_all(MOSAIC_TMP_LOG_DIR)
- } else {
- Ok(())
- }
-}
-
-pub fn debug_to_file(message: u8, pid: RawFd) -> io::Result<()> {
- let mut path = PathBuf::new();
- path.push(MOSAIC_TMP_LOG_DIR);
- path.push(format!("mosaic-{}.log", pid.to_string()));
-
- let mut file = fs::OpenOptions::new()
- .append(true)
- .create(true)
- .open(path)?;
- file.write_all(&[message])
-}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
deleted file mode 100644
index 0ea4c76f..00000000
--- a/src/utils/mod.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-pub mod consts;
-pub mod logging;
-pub mod shared;
diff --git a/src/utils/shared.rs b/src/utils/shared.rs
deleted file mode 100644
index 1d8ca5c3..00000000
--- a/src/utils/shared.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-use std::{iter, str::from_utf8};
-
-use strip_ansi_escapes::strip;
-
-pub fn ansi_len(s: &str) -> usize {
- from_utf8(&strip(s.as_bytes()).unwrap())
- .unwrap()
- .chars()
- .count()
-}
-
-pub fn pad_to_size(s: &str, rows: usize, columns: usize) -> String {
- s.lines()
- .map(|l| [l, &str::repeat(" ", columns - ansi_len(l))].concat())
- .chain(iter::repeat(str::repeat(" ", columns)))
- .take(rows)
- .collect::<Vec<_>>()
- .join("\n\r")
-}