Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit e9c5f77

Browse files
committed
Merge branch 'develop' and bump to v0.1.3
2 parents 2a9c712 + c41cb83 commit e9c5f77

File tree

5 files changed

+60
-19
lines changed

5 files changed

+60
-19
lines changed

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "zbox"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
authors = ["Bo Lu"]
5-
description = "Zbox is a zero-knowledge, privacy-focused embeddable file system."
5+
description = "Zbox is a zero-details, privacy-focused embeddable file system."
66
documentation = "https://docs.rs/zbox"
77
homepage = "https://github.com/zboxfs/zbox"
88
repository = "https://github.com/zboxfs/zbox"
@@ -13,7 +13,7 @@ license = "Apache-2.0"
1313
build = "build.rs"
1414

1515
[badges]
16-
circle-ci = { repository = "zboxfs/zbox" }
16+
travis-ci = { repository = "zboxfs/zbox" }
1717

1818
[lib]
1919
name = "zbox"

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
[![license](https://img.shields.io/github/license/zboxfs/zbox.svg?style=flat-square)](https://github.com/zboxfs/zbox)
88
[![GitHub stars](https://img.shields.io/github/stars/zboxfs/zbox.svg?style=social&label=Stars)](https://github.com/zboxfs/zbox)
99

10-
Zbox is a zero-knowledge, privacy-focused embeddable file system. Its goal is
10+
Zbox is a zero-details, privacy-focused embeddable file system. Its goal is
1111
to help application store files securely, privately and reliably. By
1212
encapsulating files and directories into an encrypted repository, it provides
1313
a virtual file system and exclusive access to authorised application.
1414

1515
Unlike other system-level file systems, such as [ext4], [XFS] and [Btrfs], which
1616
provide shared access to multiple processes, Zbox is a file system that runs
17-
in the same memory space as the application. It only provide access to one
17+
in the same memory space as the application. It only provides access to one
1818
process at a time.
1919

2020
By abstracting IO access, Zbox supports a variety of underlying storage layers.
21-
Memory and OS file system are supported, RDBMS and key-value object store
21+
Memory and OS file system are supported now, RDBMS and key-value object store
2222
supports are coming soon.
2323

2424
## Disclaimer
@@ -50,7 +50,7 @@ Many OS-level file systems support encryption, such as [EncFS], [APFS] and
5050
[ZFS]. Some disk encryption tools also provide virtual file system, such as
5151
[TrueCrypt] and [VeraCrypt].
5252

53-
This diagram shows the differece between Zbox and them.
53+
This diagram shows the difference between Zbox and them.
5454

5555
![Comparison](https://www.zbox.io/svg/zbox-compare.svg)
5656

@@ -106,11 +106,11 @@ zbox = "~0.1"
106106
extern crate zbox;
107107

108108
use std::io::{Read, Write};
109-
use zbox::{zbox_init, RepoOpener, OpenOptions};
109+
use zbox::{init_env, RepoOpener, OpenOptions};
110110

111111
fn main() {
112112
// initialise zbox environment, called first
113-
zbox_init();
113+
init_env();
114114

115115
// create and open a repository in current OS directory
116116
let mut repo = RepoOpener::new()
@@ -139,7 +139,7 @@ fn main() {
139139

140140
## Build with Docker
141141

142-
Zbox comes with Docker support, it is based on rust:latest and [libsodium] is
142+
Zbox comes with Docker support, it is based on [rust:latest] and [libsodium] is
143143
included. Check the [Dockerfile](Dockerfile) for the details.
144144

145145
First, we build the Docker image which can be used to compile Zbox, run below
@@ -189,4 +189,4 @@ file for details.
189189
[ZFS]: https://en.wikipedia.org/wiki/ZFS
190190
[TrueCrypt]: http://truecrypt.sourceforge.net
191191
[VeraCrypt]: https://veracrypt.codeplex.com
192-
192+
[rust:latest]: https://hub.docker.com/_/rust/

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Zbox is a zero-knowledge, privacy-focused embeddable file system.
1+
//! Zbox is a zero-details, privacy-focused embeddable file system.
22
//!
33
//! It keeps files securely, privately and reliably on underlying storages.
44
//! By encapsulating files and directories into an encrypted repository, it
@@ -8,8 +8,8 @@
88
//! The most core part of this module is [`Repo`] and [`File`], which provides
99
//! most file system operations and file I/O.
1010
//!
11-
//! - [`Repo`] provides similar file system manipulation methods as [`std::fs`]
12-
//! - [`File`] provides similar file I/O methods as [`std::fs::File`]
11+
//! - [`Repo`] provides similar file system manipulation methods to [`std::fs`]
12+
//! - [`File`] provides similar file I/O methods to [`std::fs::File`]
1313
//!
1414
//! [`init_env`] initialises the environment and should be called before
1515
//! any other methods provied by Zbox.

src/repo.rs

+22
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct RepoOpener {
6363
cost: Cost,
6464
cipher: Cipher,
6565
create: bool,
66+
create_new: bool,
6667
read_only: bool,
6768
}
6869

@@ -109,7 +110,21 @@ impl RepoOpener {
109110
self
110111
}
111112

113+
/// Sets the option to always create a new repository.
114+
///
115+
/// This option indicates whether a new repository will be created. No
116+
/// repository is allowed to exist at the target location.
117+
pub fn create_new(&mut self, create_new: bool) -> &mut Self {
118+
self.create_new = create_new;
119+
if create_new {
120+
self.create = true;
121+
}
122+
self
123+
}
124+
112125
/// Sets the option for read-only mode.
126+
///
127+
/// This option cannot be true with either `create` or `create_new` is true.
113128
pub fn read_only(&mut self, read_only: bool) -> &mut Self {
114129
self.read_only = read_only;
115130
self
@@ -134,6 +149,9 @@ impl RepoOpener {
134149
/// After a repository is opened, all of the other functions provided by
135150
/// Zbox will be thread-safe.
136151
///
152+
/// The application should destroy the password as soon as possible after
153+
/// calling this function.
154+
///
137155
/// # Errors
138156
///
139157
/// Open a memory based repository without enable `create` option will
@@ -144,6 +162,9 @@ impl RepoOpener {
144162
return Err(Error::InvalidArgument);
145163
}
146164
if Repo::exists(uri)? {
165+
if self.create_new {
166+
return Err(Error::AlreadyExists);
167+
}
147168
Repo::open(uri, pwd, self.read_only)
148169
} else {
149170
Repo::create(uri, pwd, self.cost, self.cipher)
@@ -166,6 +187,7 @@ impl Default for RepoOpener {
166187
cost: Cost::default(),
167188
cipher: default_cipher,
168189
create: false,
190+
create_new: false,
169191
read_only: false,
170192
}
171193
}

tests/repo.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ fn repo_oper() {
3939
// case #3: open repo in read-only mode
4040
let path = base.clone() + "/repo3";
4141
{
42-
RepoOpener::new()
43-
.create(true)
44-
.read_only(true)
45-
.open(&path, &pwd)
46-
.is_err();
42+
assert!(
43+
RepoOpener::new()
44+
.create(true)
45+
.read_only(true)
46+
.open(&path, &pwd)
47+
.is_err()
48+
);
4749
RepoOpener::new().create(true).open(&path, &pwd).unwrap();
4850
}
4951
let mut repo = RepoOpener::new().read_only(true).open(&path, &pwd).unwrap();
@@ -79,4 +81,21 @@ fn repo_oper() {
7981
{
8082
assert!(RepoOpener::new().open("mem://foo", &pwd).is_err());
8183
}
84+
85+
// case #6: test create_new option
86+
{
87+
let path = base.clone() + "/repo6";
88+
RepoOpener::new()
89+
.create_new(true)
90+
.open(&path, &pwd)
91+
.unwrap();
92+
assert_eq!(
93+
RepoOpener::new()
94+
.create_new(true)
95+
.open(&path, &pwd)
96+
.unwrap_err(),
97+
Error::AlreadyExists
98+
);
99+
RepoOpener::new().create(true).open(&path, &pwd).unwrap();
100+
}
82101
}

0 commit comments

Comments
 (0)