Skip to content

Further work ... #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 70 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
2be51a3
add accessors for the underlying stat data
cehteh Apr 17, 2021
bba0687
FIX: make use of SimpleType::Unknown in simple_type()
cehteh Apr 18, 2021
c502cc2
FIX: use u32 for the 'dev' values
cehteh Apr 18, 2021
c8f364d
Changes to make macos happy
cehteh Apr 18, 2021
39fc803
FIX: replace ino_t with u64 to comply with statx
cehteh Apr 19, 2021
815357e
Add/Refactor Dir::list() -> DirIter ctor
cehteh Apr 19, 2021
8647f93
FIX: fixes previous commit, adds special O_PATH funcs
cehteh Apr 20, 2021
d567fb1
rename *_path to *_lite, improve docs, provide impl for non linux
cehteh Apr 21, 2021
e5e9c5b
New: clone_dirfd() may fix #34, ADD: FdType machinery, libc_ok()
cehteh Apr 21, 2021
9d48913
cosmetics: use libc_ok() where applicable
cehteh Apr 21, 2021
fcf92fa
add clone_upgrade()/clone_downgrade(), fix list_self()
cehteh Apr 21, 2021
abef3ec
Store inode in Entry, add accessor
cehteh Apr 19, 2021
ffe5d3f
use types from 'struct stat' instead 'struct statx'
cehteh Apr 21, 2021
726958c
Merge branch 'entry_metadata_feature' into cehteh
cehteh Apr 22, 2021
954a9cc
Merge branch 'list_feature' into cehteh
cehteh Apr 22, 2021
6b4d359
start abstracting OS capabilities into features
cehteh Apr 22, 2021
76a795d
impl Send for `DirIter`
wmanley Apr 24, 2021
076ba5c
WIP: Add new 'conf_test' for build time configuration, o_path check
cehteh Apr 27, 2021
69acef0
add conf_tests for o_directory|search|tmpfile
cehteh Apr 27, 2021
34905a5
add the remaining tests (for now), remove a misleading note
cehteh Apr 27, 2021
c8fed25
FIX: The unnamed_tmp_file_link test needs o_tmpfile and link_file_at
cehteh Apr 27, 2021
7cf2583
WIP/FIX: test osx fcntl() returning O_DIRECTORY
cehteh Apr 27, 2021
c43ab67
notice about O_SEARCH when cloning
cehteh Apr 28, 2021
4b90fcb
add 'is_dir()' check, remove the 'test_open_file()' test
cehteh Apr 28, 2021
ec29aca
Add flags builder for 'Dir' objects
cehteh Apr 29, 2021
43b5cdf
Rename the builder ctor from new() to flags()
cehteh Apr 30, 2021
f57123b
Add DirMethodFlags builder
cehteh Apr 30, 2021
313cd86
bump conf_test version to 0.2
cehteh Apr 30, 2021
296d5e5
forgotten to enable the 'flag_reuse' tests
cehteh Apr 30, 2021
b352700
test github CI again
cehteh Apr 30, 2021
2dce4b9
Create rust.yml
cehteh Apr 30, 2021
9664800
Merge pull request #2 from cehteh/github-ci-test
cehteh Apr 30, 2021
d22b9d4
Remove the '*_lite()' versions of open() and sub_dir()
cehteh May 1, 2021
273b310
Merge remote-tracking branch 'github/master'
cehteh May 1, 2021
809a318
export O_PATH, O_SEARCH, O_DIRECTORY flags
cehteh May 1, 2021
565fe8d
Merge pull request #3 from wmanley/DirIter-impl-Send
cehteh May 1, 2021
9eb43a3
Make this an fork named 'openat_ct' for the time being
cehteh Oct 18, 2021
0076547
make the DirIter Entry members public
cehteh Nov 16, 2021
400ea34
v0.2.0-pre0 bump edition to 2021
cehteh Nov 16, 2021
1c66e11
Add remove_recursive() and remove_recursive_atomic()
cehteh Nov 19, 2021
05b5b15
Bump prerelease version
cehteh Nov 19, 2021
d123ec8
FIX: remove_recursive_atomic
cehteh Nov 19, 2021
42c8bff
Fix: make remove_recursive_atomic() work with subdirs
cehteh Nov 20, 2021
96f8b1a
Fix the types Metadata member functions return once for all
cehteh Dec 25, 2021
17af589
fix Cargo.toml, bump to 0.2-pre4
cehteh Dec 25, 2021
9c2c8ab
impl Debug for Metadata
cehteh Jan 14, 2022
a3d5ef2
add metadata method for iterator entries
cehteh Jan 14, 2022
2b89f0b
0.2.0-pre5: Entries::metadata() and Metadata Debug
cehteh Jan 14, 2022
9c0634f
move 'Entry' to list.rs
cehteh Jan 15, 2022
42b4b95
WIP: Add smoke test for Entry::metadata()
cehteh Jan 15, 2022
96d121c
FIX: Close dir handle when the last strong reference becomes dropped
cehteh Jan 31, 2022
87e0352
FIX: proper DirHandle impl
cehteh Feb 2, 2022
5fd8475
move struct Dir into dir.rs
cehteh Feb 2, 2022
3374723
Add Dir::close()
cehteh Feb 2, 2022
75aa66f
Make RawFd atomic
cehteh Feb 2, 2022
bb824c3
Big cleanup 1/3: rustfmt with new rustfmt.toml
cehteh Feb 2, 2022
8410c13
Big cleanup 2/3: make clippy happy
cehteh Feb 2, 2022
43d77e6
Big cleanup 3/3: remove 0.1.x deprecated functions
cehteh Feb 2, 2022
4a19846
remove 'unsafe' from from_raw_fd_checked()
cehteh Feb 2, 2022
88cb5f3
v0.2.0-pre6: Improvements, Cleanup and stabilization
cehteh Feb 2, 2022
e44fc88
Fix: 'Entry' got lost from export, don't make members public
cehteh Feb 2, 2022
a0736bb
FIX: supporting close needs RwLocks, atomics are racy
cehteh Feb 3, 2022
2cc902b
0.2.0-pre9: Revert explicit file handle closing
cehteh Feb 4, 2022
e477fc8
add github ci/dependabot
cehteh Mar 28, 2022
e5a734b
improve gitignore
cehteh Mar 29, 2022
add0ff8
bump conf_test version
cehteh Jul 29, 2022
d3c8de4
v0.2.0-pre10: FIX: https://github.com/tailhook/openat/issues/46
cehteh Jul 29, 2022
82bc56d
fix: missing arg on the DUPFD_CLOEXEC confcheck
cehteh Jul 30, 2022
b2cbb65
New method `Dir::sync`
zackw Dec 12, 2023
e054d63
Merge pull request #5 from zackw/master
cehteh Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "cargo"
directory: "/" # Location of package manifests
schedule:
interval: "daily"
labels:
- "improvement"
assignees:
- "cehteh"

24 changes: 24 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Rust

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Clippy
run: cargo clippy --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Cargo.lock
/target
/tmp
.tests-*
40 changes: 30 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
[package]
name = "openat"
name = "openat_ct"
description = """
A wrapper around openat, symlinkat, and similar system calls
forked and improved from https://crates.io/crates/openat
"""
license = "MIT/Apache-2.0"
readme = "README.md"
keywords = ["open", "openat", "filesystem", "fs"]
categories = ["filesystem", "api-bindings"]
repository = "https://github.com/tailhook/openat"
homepage = "https://github.com/tailhook/openat"
documentation = "http://docs.rs/openat"
version = "0.1.21"
authors = ["[email protected]"]
edition = "2018"
repository = "https://github.com/cehteh/openat"
homepage = "https://github.com/cehteh/openat"
documentation = "http://docs.rs/openat_ct"
version = "0.2.0-pre10"
authors = ["[email protected], [email protected]"]
edition = "2021"

[features]
default = []
linux = ["o_path", "o_directory", "o_tmpfile", "statx", "proc_self_fd", "link_file_at", "rename_exchange", "renameat_flags", "fcntl_f_dupfd_cloexec"]
#NOTE(cehteh): eventually provide some baseline configs for other OS'es (for cross compilation)
o_path = []
o_directory = []
o_tmpfile = []
o_search = []
fcntl_o_directory = []
fcntl_f_dupfd_cloexec = []
proc_self_fd = []
link_file_at = []
renameat_flags = []
rename_exchange = []
statx = []

[dependencies]
libc = "0.2.34"
libc = "0.2"

[build-dependencies]
conf_test = "0.3.0"

[dev-dependencies]
argparse = "0.2.1"
tempfile = "3.0.3"
argparse = "0.2"
tempfile = "3.0"
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
Openat Crate
============
Openat (ct) Crate
=================

**Status: Beta**

[Documentation](https://docs.rs/openat) |
[Github](https://github.com/tailhook/openat) |
[Crate](https://crates.io/crates/openat)
[Documentation](https://docs.rs/openat_ct) |
[Github](https://github.com/cehteh/openat) |
[Crate](https://crates.io/crates/openat_ct)


The interface to ``openat``, ``symlinkat``, and other functions in ``*at``
family.

About this Fork
===============

This is a fork of the original 'openat' at https://github.com/tailhook/openat

The objective is to fix existing Issues and add features as required. An eventual goal would
be to get this merged back into upstream. In most cases the API should stay backward
compatible with the original openat (Unless functionality and fixes dictate changes).

It can be used as drop in replacement by aliasing the import:

use openat_ct as openat;


Dependent crates
================

Expand Down
50 changes: 32 additions & 18 deletions benches/count_processes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,51 @@
extern crate openat;
extern crate test;


use std::fs::read_dir;
use std::str::from_utf8;
use std::os::unix::ffi::OsStrExt;
use test::Bencher;
use std::str::from_utf8;

use test::Bencher;
use openat::Dir;


#[bench]
fn procs_stdlib(b: &mut Bencher) {
b.iter(|| {
read_dir("/proc").unwrap().filter(|r| {
r.as_ref().ok()
.and_then(|e| from_utf8(e.file_name().as_bytes()).ok()
// pid is everything that can be parsed as a number
.and_then(|s| s.parse::<u32>().ok()))
.is_some()
}).count()
read_dir("/proc")
.unwrap()
.filter(|r| {
r.as_ref()
.ok()
.and_then(|e| {
from_utf8(e.file_name().as_bytes())
.ok()
// pid is everything that can be parsed as a number
.and_then(|s| s.parse::<u32>().ok())
})
.is_some()
})
.count()
});
}

#[bench]
fn procs_openat(b: &mut Bencher) {
b.iter(|| {
Dir::open("/proc").unwrap().list_dir(".").unwrap().filter(|r| {
r.as_ref().ok()
.and_then(|e| from_utf8(e.file_name().as_bytes()).ok()
// pid is everything that can be parsed as a number
.and_then(|s| s.parse::<u32>().ok()))
.is_some()
}).count()
Dir::open("/proc")
.unwrap()
.list_dir(".")
.unwrap()
.filter(|r| {
r.as_ref()
.ok()
.and_then(|e| {
from_utf8(e.file_name().as_bytes())
.ok()
// pid is everything that can be parsed as a number
.and_then(|s| s.parse::<u32>().ok())
})
.is_some()
})
.count()
});
}
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use conf_test::ConfTest;

fn main() {
ConfTest::run();
}
10 changes: 10 additions & 0 deletions conf_tests/fcntl_f_dupfd_cloexec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extern crate libc;

fn main() {
unsafe {
let conf_tests = std::ffi::CString::new("conf_tests").unwrap();
let fd = libc::open(conf_tests.as_ptr(), libc::O_DIRECTORY | libc::O_RDONLY);

let dup = libc::fcntl(fd, libc::F_DUPFD_CLOEXEC, 0);
}
}
16 changes: 16 additions & 0 deletions conf_tests/fcntl_o_directory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extern crate libc;

fn main() {
unsafe {
let conf_tests = std::ffi::CString::new("conf_tests").unwrap();
let fd = libc::open(conf_tests.as_ptr(), libc::O_DIRECTORY | libc::O_RDONLY);

let flags = libc::fcntl(fd, libc::F_GETFL);

if flags != -1 && flags & libc::O_DIRECTORY != 0 {
std::process::exit(0);
} else {
std::process::exit(1);
}
}
}
13 changes: 13 additions & 0 deletions conf_tests/link_file_at.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extern crate libc;

fn main() {
//NOTE(cehteh): same as the proc_self_fd test, maybe we need something smarter in future
unsafe {
let conf_tests = std::ffi::CString::new("/proc/self/fd/0").unwrap();
if libc::open(conf_tests.as_ptr(), libc::O_RDONLY) != -1 {
std::process::exit(0);
} else {
std::process::exit(1);
}
}
}
8 changes: 8 additions & 0 deletions conf_tests/o_directory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern crate libc;

fn main() {
unsafe {
let conf_tests = std::ffi::CString::new("conf_tests").unwrap();
libc::open(conf_tests.as_ptr(), libc::O_DIRECTORY);
}
}
8 changes: 8 additions & 0 deletions conf_tests/o_path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern crate libc;

fn main () {
unsafe {
let conf_tests = std::ffi::CString::new("conf_tests").unwrap();
libc::open(conf_tests.as_ptr(), libc::O_PATH);
}
}
8 changes: 8 additions & 0 deletions conf_tests/o_search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern crate libc;

fn main() {
unsafe {
let conf_tests = std::ffi::CString::new("conf_tests").unwrap();
libc::open(conf_tests.as_ptr(), libc::O_SEARCH);
}
}
10 changes: 10 additions & 0 deletions conf_tests/o_tmpfile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extern crate libc;

fn main () {
unsafe {
let conf_tests = std::ffi::CString::new("conf_tests").unwrap();
libc::open(conf_tests.as_ptr(),
libc::O_TMPFILE | libc::O_RDWR,
libc::S_IRUSR | libc::S_IWUSR);
}
}
12 changes: 12 additions & 0 deletions conf_tests/proc_self_fd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extern crate libc;

fn main() {
unsafe {
let conf_tests = std::ffi::CString::new("/proc/self/fd/0").unwrap();
if libc::open(conf_tests.as_ptr(), libc::O_RDONLY) != -1 {
std::process::exit(0);
} else {
std::process::exit(1);
}
}
}
5 changes: 5 additions & 0 deletions conf_tests/rename_exchange.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern crate libc;

fn main() {
let does_rename_exchange_exist = libc::RENAME_EXCHANGE;
}
5 changes: 5 additions & 0 deletions conf_tests/renameat_flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern crate libc;

fn main() {
let does_renameat2_exist = libc::SYS_renameat2;
}
14 changes: 7 additions & 7 deletions examples/exchange.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
extern crate argparse;
extern crate openat;

use std::process::exit;
use std::path::PathBuf;
use std::process::exit;

use openat_ct as openat;
use argparse::{ArgumentParser, Parse};
use openat::Dir;

#[cfg(not(target_os="linux"))]
#[cfg(not(target_os = "linux"))]
fn main() {
println!("Atomic exchange is not supported on this platform")
}

#[cfg(target_os="linux")]
#[cfg(target_os = "linux")]
fn main() {
let mut path1 = PathBuf::new();
let mut path2 = PathBuf::new();
Expand All @@ -32,8 +30,10 @@ fn main() {
}
let parent = path1.parent().expect("path must have parent directory");
let dir = Dir::open(parent).expect("can open directory");
#[cfg(feature = "rename_exchange")]
dir.local_exchange(
path1.file_name().expect("path1 must have filename"),
path2.file_name().expect("path2 must have filename"),
).expect("can rename");
)
.expect("can rename");
}
22 changes: 22 additions & 0 deletions rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Rust

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
17 changes: 17 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version = "Two"
#max_width = 120
#comment_width = 120
enum_discrim_align_threshold = 40
struct_field_align_threshold = 40

#license_template_path
format_macro_matchers = true
normalize_comments = true
overflow_delimited_expr = true
reorder_impl_items = true
reorder_imports = false
group_imports = "StdExternalCrate"
use_field_init_shorthand = true

use_try_shorthand = true
normalize_doc_attributes = true
Loading