From c8dc1635f8a921269f714117f414bbc7ba24f9fd Mon Sep 17 00:00:00 2001 From: moxie Date: Sat, 14 Mar 2026 10:28:08 +0200 Subject: refactor: consolidate modules and improve structure --- lua/muwiki/fs.lua | 85 ------------------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 lua/muwiki/fs.lua (limited to 'lua/muwiki/fs.lua') diff --git a/lua/muwiki/fs.lua b/lua/muwiki/fs.lua deleted file mode 100644 index 6d53c0a..0000000 --- a/lua/muwiki/fs.lua +++ /dev/null @@ -1,85 +0,0 @@ -local paths = require('muwiki.paths') - -local M = {} - -function M.file_exists(path) - local stat = vim.uv.fs_stat(path) - return stat and stat.type == 'file' -end - -function M.dir_exists(path) - local stat = vim.uv.fs_stat(path) - return stat and stat.type == 'directory' -end - -function M.create_dir_safely(dirpath, wiki_root) - if not paths.is_within_wiki(dirpath, wiki_root) then - return false, 'Directory is outside wiki root' - end - - if M.dir_exists(dirpath) then - return true, nil - end - - if vim.fn.mkdir(dirpath, 'p') ~= 1 then - return false, 'Failed to create directory' - end - - if not paths.is_within_wiki(dirpath, wiki_root) then - vim.fn.delete(dirpath, 'd') - return false, 'Symlink attack detected' - end - - return true, nil -end - -function M.ensure_parent_dirs(filepath, wiki_root, mode, callback) - local dirpath = vim.fs.dirname(filepath) - - if M.dir_exists(dirpath) then - if callback then - callback(true) - end - return true - end - - local function do_create() - local success, err = M.create_dir_safely(dirpath, wiki_root) - if not success then - vim.notify(string.format('Cannot create directory: %s', err), vim.log.levels.ERROR) - if callback then - callback(false) - end - return false - end - - if mode == 'notify' then - vim.notify(string.format('Created directory: %s', dirpath), vim.log.levels.INFO) - end - - if callback then - callback(true) - end - return true - end - - if mode == 'prompt' then - vim.ui.select({ 'Yes', 'No' }, { - prompt = string.format('Directory does not exist. Create %s?', dirpath), - }, function(choice) - if choice == 'Yes' then - do_create() - else - vim.notify('Directory creation cancelled', vim.log.levels.INFO) - if callback then - callback(false) - end - end - end) - return nil - end - - return do_create() -end - -return M -- cgit v1.2.3