Skip to content

Commit

Permalink
Use whoami instead of users for better compatibility (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimahriman authored Jun 17, 2024
1 parent 4e04682 commit 16f6feb
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 33 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter --manifest-path python/Cargo.toml
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
with:
args: --release --out dist --find-interpreter --manifest-path python/Cargo.toml
sccache: 'true'
manylinux: auto

- name: Upload wheels
if: github.ref == 'refs/heads/master'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
matrix:
os:
- ubuntu-latest
# - macos-11
# - windows-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}

steps:
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
matrix:
os:
- ubuntu-latest
# - macos-11
# - macos-latest
# - windows-latest
runs-on: ${{ matrix.os }}
env:
Expand Down
39 changes: 28 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ cipher = "0.4"
crc = "3.2"
ctr = "0.9"
des = "0.8"
# Just used for benchmarks
fs-hdfs3 = { version = "0.1.12", optional = true }
futures = "0.3"
g2p = "1"
hex = "0.4"
Expand All @@ -42,9 +40,13 @@ socket2 = "0.5"
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "net", "io-util", "macros", "sync", "time"] }
url = "2"
users = { version = "0.11", default-features = false }
uuid = { version = "1", features = ["v4"] }
which = { version = "4", optional = true }
whoami = "1"

[target.'cfg(unix)'.dependencies]
# Just used for benchmarks
fs-hdfs3 = { version = "0.1.12", optional = true }

[build-dependencies]
prost-build = { version = "0.12", optional = true }
Expand Down
14 changes: 9 additions & 5 deletions rust/benches/io.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashSet;

#[allow(unused_imports)]
use bytes::{Buf, BufMut, BytesMut};
use criterion::*;
use hdfs::hdfs::get_hdfs;
use hdfs_native::{
minidfs::{DfsFeatures, MiniDfs},
Client, WriteOptions,
Expand Down Expand Up @@ -49,8 +49,9 @@ fn bench(c: &mut Criterion) {
})
});
group.sample_size(50);
#[cfg(unix)]
group.bench_function("read-libhdfs", |b| {
let fs = get_hdfs().unwrap();
let fs = hdfs::hdfs::get_hdfs().unwrap();
b.iter(|| {
let mut buf = BytesMut::zeroed(ints_to_write * 4);
let mut bytes_read = 0;
Expand Down Expand Up @@ -79,8 +80,9 @@ fn bench(c: &mut Criterion) {
.iter(|| async { reader.read_range(0, reader.file_length()).await.unwrap() })
});
group.sample_size(50);
#[cfg(unix)]
group.bench_function("read-libhdfs", |b| {
let fs = get_hdfs().unwrap();
let fs = hdfs::hdfs::get_hdfs().unwrap();
b.iter(|| {
let mut buf = BytesMut::zeroed(ints_to_write * 4);
let mut bytes_read = 0;
Expand Down Expand Up @@ -120,8 +122,9 @@ fn bench(c: &mut Criterion) {
})
});
group.sample_size(10);
#[cfg(unix)]
group.bench_function("write-libhdfs", |b| {
let fs = get_hdfs().unwrap();
let fs = hdfs::hdfs::get_hdfs().unwrap();
b.iter(|| {
let mut buf = buf.clone();
let writer = fs.create_with_overwrite("/bench-write", true).unwrap();
Expand Down Expand Up @@ -154,8 +157,9 @@ fn bench(c: &mut Criterion) {
})
});
group.sample_size(10);
#[cfg(unix)]
group.bench_function("write-libhdfs", |b| {
let fs = get_hdfs().unwrap();
let fs = hdfs::hdfs::get_hdfs().unwrap();
b.iter(|| {
let mut buf = buf.clone();
let writer = fs
Expand Down
5 changes: 2 additions & 3 deletions rust/benches/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashSet;

use criterion::*;
use hdfs::hdfs::get_hdfs;
use hdfs_native::{minidfs::MiniDfs, Client, WriteOptions};

fn bench(c: &mut Criterion) {
Expand All @@ -25,14 +24,14 @@ fn bench(c: &mut Criterion) {
.unwrap();
});

let fs = get_hdfs().unwrap();

let mut group = c.benchmark_group("rpc");
group.bench_function("getFileInfo-native", |b| {
b.to_async(&rt)
.iter(|| async { client.get_file_info("/bench").await.unwrap() })
});
#[cfg(unix)]
group.bench_function("getFileInfo-libhdfs", |b| {
let fs = hdfs::hdfs::get_hdfs().unwrap();
b.iter(|| fs.get_file_status("/bench").unwrap())
});
}
Expand Down
10 changes: 2 additions & 8 deletions rust/src/security/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fs;
use std::io;
use std::path::PathBuf;

use users::get_current_username;
use whoami::username;

use crate::proto::common::CredentialsProto;
use crate::proto::common::TokenProto;
Expand Down Expand Up @@ -333,13 +333,7 @@ impl User {
}

pub(crate) fn get_simpler_user() -> UserInfo {
let effective_user = env::var(HADOOP_USER_NAME).ok().unwrap_or_else(|| {
get_current_username()
.unwrap()
.to_str()
.unwrap()
.to_string()
});
let effective_user = env::var(HADOOP_USER_NAME).ok().unwrap_or_else(username);
UserInfo {
real_user: None,
effective_user: Some(effective_user),
Expand Down

0 comments on commit 16f6feb

Please sign in to comment.