Skip to content

Commit

Permalink
Complete README (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lylex committed Dec 22, 2018
1 parent aadca78 commit 11e2e6d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 11 deletions.
132 changes: 130 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,130 @@
# drm
Not ready yet
<p align="center">
<img
src="logo.png"
width="300" height="200" border="0" alt="drm">
<br>
<a href="https://travis-ci.org/lylex/drm"><img src="https://img.shields.io/travis/lylex/drm.svg?style=flat-square" alt="Build Status"></a>
<a href="https://goreportcard.com/report/github.com/lylex/drm"><img src="https://goreportcard.com/badge/github.com/lylex/drm?style=flat-square" alt="Go Report Card"></a>
<a href="https://godoc.org/github.com/lylex/drm"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a>
<a href="https://github.com/lylex/drm/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" alt="License"></a>
<a href="https://github.com/lylex/drm"><img src="https://img.shields.io/codecov/c/github/lylex/drm/master.svg?style=flat-square" alt="Code Coverage"></a>
</p>

Drm, pronounced like "dream". It is a tiny tool to avoid tragedies caused by `rm`. Actually, I did decide to write it after I `rm`ed a whole day's hard-work. It can replace `rm` in basic function, and support resume deleted files before it reaches the expiration days(e.g. 30 days).

Features
========

- `rm` a file or directory
- View deleted files or directories
- Resume deleted objects
- Auto-purge delete object after configed TTL days


Getting Started
===============

## Installing

### MacOS

Download released packages from [release page](https://github.com/lylex/drm/releases), e.g. drm_v0.1.0_Darwin_x86_64.tar.gz

Run the following commands:

```shell
tar -xzf drm_v0.1.0.tar.gz
cd drm
sudo ./scripts/mac/install_mac.sh
```

### Linux

Download binary from [release page](https://github.com/lylex/drm/releases), e.g. drm_v0.1.0_Linux_x86_64.deb

run the following commands:

```shell
sudo dpkg -i drm_v0.1.0_Linux_x86_64.deb
```

## Use

After installation, binary is copied to executable path, and alias to replace `rm` is added to /etc/profile. Now you can use `drm` just like `rm` which you are familiar with.

```
$ rm --help
This application is used to rm files with a latency.
Usage:
drm [flags]
drm [command]
Available Commands:
help Help about any command
list list all the deleted objects
restore restore one or more the deleted objects
Flags:
--config string config file (default is /etc/drm/drm.conf) (default "/etc/drm/drm.conf")
-f, --force ignore nonexistent files and arguments, never prompt
-h, --help help for drm
-r, --recursive remove directories and their contents recursively or not
--version version for drm
Use "drm [command] --help" for more information about a command.
```

### Delete a directory

Just run `rm -rf ./dir` or `drm -rf ./dir`, since they are alias now.

### List deleted files

```
drm list
```

or

```
rm list
```

And you will see something like:

```
Name Path DeleteAt ID
---- ---- -------- --
LICENSE /Users/lylex/workspace/drm/dist/temp 2018-12-22 22:38:13 Rvv3Jg
README.md /Users/lylex/workspace/drm/dist/temp 2018-12-22 22:38:34 SHgtPG
```

### Resume a file a directory

Run

```
drm restore LICENSE
```

Or

```
rm restore LICENSE
```

Then `LICENSE` will be resumed.


## ✋ Contributing

I will be so happay if this tiny tool can help you in any way. And I am really glad if you can help make it better. So please feel free to contribute by

- Opening an [issue](https://github.com/lylex/drm/issues/new)
- Sending me feedback via [email](mailto://xuqianzhou@gmail.com)

## License

Drm source code is available under the MIT [License](/LICENSE).
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ func initConfig() {
utils.ErrExit("Failed to read configuration file: %+v\n", err)
}

// read config from enviroment virable.
// read config from environment virable.
viper.AutomaticEnv()
}
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pkg/blobs/blob_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func getBlobGroup(filename string) (*blobGroup, error) {
raw = val
return nil
})
if err != nil {
return nil, err
}

if raw == "" {
return nil, nil
Expand Down
7 changes: 2 additions & 5 deletions pkg/blobs/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (

var (
// ErrOperateDB is returned when unknow error hanppend from database.
ErrOperateDB = errors.New("error happended when operating database")
ErrOperateDB = errors.New("error happened when operating database")

// ErrNotFound represents no record found.
ErrNotFound = errors.New("not found")
Expand Down Expand Up @@ -77,11 +77,8 @@ func (b *Blob) Save() error {
if err = bg.add(b); err != nil {
return err
}
if err = bg.save(); err != nil {
return err
}

return nil
return bg.save()
}

// Destroy deletes a blob from database.
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestMarshal(t *testing.T) {
t.Errorf("failed to marshal object, expect %v, got %v", expect, result)
}
if err != nil {
t.Errorf("unexpected error occured: %v", err)
t.Errorf("unexpected error occurred: %v", err)
}
}

Expand All @@ -47,7 +47,7 @@ func TestUnmarshal(t *testing.T) {
t.Errorf("failed to unmarshal string to object: expect %v, got %v", expect, group)
}
if err != nil {
t.Errorf("unexpected error occured: %v", err)
t.Errorf("unexpected error occurred: %v", err)
}
}
func TestGenerateRandString(t *testing.T) {
Expand All @@ -66,7 +66,7 @@ func TestGenerateRandString(t *testing.T) {
}
}

// We deside to ignore the tiny probability.
// We decide to ignore the tiny probability.
if GenerateRandString(6) == GenerateRandString(6) {
t.Errorf("Generate radom string should not be the same")
}
Expand Down

0 comments on commit 11e2e6d

Please sign in to comment.