Skip to content

Commit d985c51

Browse files
aw-server: Fix compilation on android
1 parent b14a173 commit d985c51

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

aw-server/src/android/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::ffi::{CStr, CString};
77
use std::os::raw::c_char;
88
use std::sync::Mutex;
99

10+
use crate::device_id;
1011
use crate::dirs;
1112

1213
use android_logger::Config;
@@ -111,6 +112,7 @@ pub mod android {
111112
let server_state = endpoints::ServerState {
112113
datastore: Mutex::new(openDatastore()),
113114
asset_path: PathBuf::from(asset_path),
115+
device_id: device_id::get_device_id(),
114116
};
115117

116118
let mut config = AWConfig::default();

aw-server/src/device_id.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::fs;
2+
3+
use uuid::Uuid;
4+
5+
use crate::dirs;
6+
7+
/// Retrieves the device ID, if none exists it generates one (using UUID v4)
8+
pub fn get_device_id() -> String {
9+
// I chose get_data_dir over get_config_dir since the latter isn't yet supported on Android.
10+
let mut path = dirs::get_data_dir().unwrap();
11+
path.push("device_id");
12+
if path.exists() {
13+
fs::read_to_string(path).unwrap()
14+
} else {
15+
let uuid = Uuid::new_v4().to_hyphenated().to_string();
16+
fs::write(path, &uuid).unwrap();
17+
uuid
18+
}
19+
}

aw-server/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern crate toml;
3131
#[macro_use]
3232
pub mod macros;
3333
pub mod config;
34+
pub mod device_id;
3435
pub mod dirs;
3536
pub mod endpoints;
3637
pub mod logging;

aw-server/src/main.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ extern crate getopts;
44

55
use getopts::Options;
66
use rocket::config::Environment;
7-
use uuid::Uuid;
87

98
use std::env;
10-
use std::fs;
119

1210
use aw_server::*;
1311

@@ -22,20 +20,6 @@ fn print_usage(program: &str, opts: Options) {
2220
print!("{}", opts.usage(&brief));
2321
}
2422

25-
/// Retrieves the device ID, if none exists it generates one (using UUID v4)
26-
fn get_device_id() -> String {
27-
// I chose get_data_dir over get_config_dir since the latter isn't yet supported on Android.
28-
let mut path = dirs::get_data_dir().unwrap();
29-
path.push("device_id");
30-
if path.exists() {
31-
fs::read_to_string(path).unwrap()
32-
} else {
33-
let uuid = Uuid::new_v4().to_hyphenated().to_string();
34-
fs::write(path, &uuid).unwrap();
35-
uuid
36-
}
37-
}
38-
3923
fn main() {
4024
use std::sync::Mutex;
4125

@@ -84,7 +68,7 @@ fn main() {
8468
// it will not happen there
8569
datastore: Mutex::new(aw_datastore::Datastore::new(db_path, true)),
8670
asset_path,
87-
device_id: get_device_id(),
71+
device_id: device_id::get_device_id(),
8872
};
8973

9074
endpoints::build_rocket(server_state, config).launch();

0 commit comments

Comments
 (0)