From 961e93539c14ca7e55428d504e36f5211fab4acf Mon Sep 17 00:00:00 2001 From: Sharaf Zaman Date: Fri, 1 Feb 2019 01:31:25 +0530 Subject: [PATCH] resolve symlink path --- src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a02191c..af2c9ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,8 @@ use actix_web::{server as actix_server, App}; use rlua::prelude::*; use std::{ path::{Path, PathBuf}, - result + result, + fs }; use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; use serde_json::Value; @@ -85,7 +86,13 @@ impl AppState { } // Lua arg - lua.globals().set("arg", lua.create_sequence_from(self.init_args.clone())?)?; + let mut cmd_args = self.init_args.clone(); + // if file path is symlink, then resolve + match fs::read_link(&cmd_args[0]) { + Ok(p) => cmd_args[0] = String::from(p.to_str().unwrap_or("")), + Err(_) => (), + }; + lua.globals().set("arg", lua.create_sequence_from(cmd_args)?)?; // Lua Bridge lua.exec::<_, ()>(include_str!("handlers/bridge.lua"), None)?;