Skip to content

Commit

Permalink
fix(touch_storage): remove overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
l3r8yJ committed Jun 5, 2024
1 parent 0d3c5d5 commit 32b8822
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::xml::storage::touch_storage;

#[tokio::main]
async fn main() {
touch_storage(Some("fakehub.xml")).unwrap();
touch_storage(Some("fakehub.xml"));
let app = Router::new().route("/", get(home::home));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
Expand Down
9 changes: 4 additions & 5 deletions src/xml/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
use std::fmt::Error;
use std::fs::File;

use log::info;

pub fn touch_storage(path: Option<&str>) -> Result<File, Error> {
pub fn touch_storage(path: Option<&str>) -> File {
let location = path.unwrap_or("fakehub.xml");
info!("Initializing XML storage: {location}");
match File::create(location) {
Ok(file) => {
info!("'{location}' initialized");
Ok(file)
file
}
Err(err) => {
panic!("fakehub storage failed to initialize in '{location}': {err}")
Expand All @@ -49,7 +48,7 @@ mod tests {
let temp = TempDir::new("temp")?;
let path = temp.path().join("fakehub.xml");
let storage = path.to_str();
touch_storage(storage).unwrap();
touch_storage(storage);
assert!(
path.exists(),
"storage file {:?} was not created, but should be",
Expand All @@ -63,7 +62,7 @@ mod tests {
let temp = TempDir::new("temp")?;
let path = temp.path().join("test.xml");
let storage = path.to_str();
touch_storage(storage).unwrap();
touch_storage(storage);
assert!(
path.exists(),
"storage file {:?} was not created, but should be",
Expand Down

0 comments on commit 32b8822

Please sign in to comment.