fixed file permission error with a 'truncate option, used racket-native file permission-changing function
parent
4c1089e459
commit
d06d952cdd
21
README.md
21
README.md
|
@ -15,27 +15,6 @@ Now the default directory and todo list file have better default permissions:
|
|||
|
||||
# Todos
|
||||
|
||||
- **Really weird bug to solve**: `~/.rodo/todo.txt`'s file permissions change from `rw-------` to `rw-rw-r--` (if on Ubuntu) or `rw-rw-rw` (if on Windows Subsystem for Linux) after being modified
|
||||
- For example:
|
||||
1. Create a `test.txt` file somewhere
|
||||
2. Open a Racket REPL
|
||||
3. Run the following to set `600` file permissions on the file:
|
||||
```racket
|
||||
(file-or-directory-permissions "test.txt" #o600)
|
||||
```
|
||||
4. Run `ls -l` to check the file permissions
|
||||
5. Run the following to modify the file:
|
||||
```racket
|
||||
(display-to-file "this is a test" "test.txt" #:mode 'text #:exists 'replace)
|
||||
```
|
||||
6. Run `ls -l` to check the file permissions to see that they have changed to either `rw-rw-r--` or `rw-rw-rw`
|
||||
- So far, the only solution I know of would be to do:
|
||||
```racket
|
||||
(begin
|
||||
(display-to-file "this is a test" "test.txt" #:mode 'text #:exists 'replace)
|
||||
(file-or-directory-permissions "test.txt" #o600))
|
||||
```
|
||||
- Unfortunately the above solution leaves the file readable for a split second, which would be enough for another program to read information in the files
|
||||
- Add color option to `config.rkt` file
|
||||
- Encrypt `todo.txt` file
|
||||
- Add note on `.bash_history` about items being added here before going into the `todo.txt` file
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
(provide (all-defined-out))
|
||||
|
||||
(define program-name "rodo")
|
||||
(define program-directory "~/.rodo/")
|
||||
(define program-directory (path->string (expand-user-path "~/.rodo/")))
|
||||
(define program-file "todo.txt")
|
||||
(define remove-command "rm")
|
||||
(define add-command "add")
|
||||
|
@ -10,7 +10,6 @@
|
|||
(define initialize-command "init")
|
||||
(define help-command '("-h" "--help"))
|
||||
(define path
|
||||
(expand-user-path
|
||||
(string-append
|
||||
program-directory
|
||||
program-file)))
|
||||
program-file))
|
||||
|
|
19
util.rkt
19
util.rkt
|
@ -3,20 +3,11 @@
|
|||
(require (prefix-in list: racket/list)
|
||||
(prefix-in file: racket/file)
|
||||
(prefix-in string: racket/string)
|
||||
(prefix-in system: racket/system)
|
||||
(prefix-in config: "config.rkt")
|
||||
(prefix-in messages: "messages.rkt"))
|
||||
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define (set-permissions permissions file-or-directory)
|
||||
(let* ([converted-permissions (number->string permissions)]
|
||||
[converted-file-or-directory
|
||||
(cond [(path? file-or-directory) (path->string file-or-directory)]
|
||||
[else file-or-directory])])
|
||||
(system:system
|
||||
(string-append "chmod" " " converted-permissions " " converted-file-or-directory))))
|
||||
|
||||
(define (check-for-file)
|
||||
(file-exists? config:path))
|
||||
|
||||
|
@ -24,9 +15,9 @@
|
|||
(let ([opened-file
|
||||
(open-output-file config:path
|
||||
#:mode 'text
|
||||
#:exists 'can-update)])
|
||||
#:exists 'truncate)])
|
||||
(close-output-port opened-file))
|
||||
(set-permissions 600 config:path))
|
||||
(file-or-directory-permissions config:path #o600))
|
||||
|
||||
(define (check-for-directory)
|
||||
(directory-exists? (expand-user-path
|
||||
|
@ -37,7 +28,7 @@
|
|||
(make-directory (expand-user-path
|
||||
(string-append
|
||||
config:program-directory)))
|
||||
(set-permissions 700 config:program-directory))
|
||||
(file-or-directory-permissions config:program-directory #o700))
|
||||
|
||||
(define (display-hash-ref hash-list key)
|
||||
(display (hash-ref hash-list key)))
|
||||
|
@ -119,7 +110,7 @@
|
|||
(string:string-join new-list "\n")
|
||||
config:path
|
||||
#:mode 'text
|
||||
#:exists 'replace)
|
||||
#:exists 'truncate)
|
||||
(display-item-added args)))
|
||||
|
||||
(define (add-item args)
|
||||
|
@ -139,7 +130,7 @@
|
|||
(string:string-join new-list "\n")
|
||||
config:path
|
||||
#:mode 'text
|
||||
#:exists 'replace)
|
||||
#:exists 'truncate)
|
||||
(display-item-removed removed-item)))
|
||||
|
||||
(define (remove-item args)
|
||||
|
|
Loading…
Reference in New Issue