Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 5.77 KB

file_system.md

File metadata and controls

64 lines (52 loc) · 5.77 KB

MIT Licensed Awesome       

File System

In this section we will dive into the basics of Unix based file systems. Particularly, you will discover notions of file descriptors, users / groups access permissions, special files etc.

Theory

  1. Read about typical file system structure in Unix Systems
  2. Discover unix file permissions and access modes
  3. 🚦Node.js🚦 Node.js File System
  4. 🚦Golang🚦 Working with Files in Go
  5. 🚦Python🚦 Working With Files in Python

Practical Task

  1. Create folder called file_system folder in your kottans-backend repo
  2. In file_system folder:
    • create file called secret.txt
    • grant read-write-execute permissions to owned user, read-only permission to owned group and no permissions to other users for file secret.txt. Permission indicator for this file should be: -rwxr-----
    • commit and push your changes to remote
  3. 🚦Node.js🚦 In your file_system folder create file file_system_task.js. In this file, implement a program with the following behavior:
    • Upon run (with node file_system_task.js), program checks whether or not file counter.txt exists.
    • If its not. Program creates new file counter.txt with write/read/execute access to all users. Then it writes single digit 1 into the file, closes it and exits with status code 0 (normal exit).
    • If it does exist. Program opens the file counter.txt, reads its content and checks whether or not all the content of the file is valid integer. If it's valid integer, program increments counter by one, writes new digit into the file (replaces previous one), closes the file and exits with status code 0 (normal exit). If its not valid immediately exists with status code 1 (abnormal exit).
  4. 🚦Golang🚦 In your file_system folder create file file_system_task.go. Within this file, implement program with the following behavior:
    • Upon run (with go run file_system_task.go, consider that your file_system_task.go should have main function to be executable), program checks whether or not file counter.txt exists.
    • If its not. Program creates new file counter.txt with write/read/execute access to all users. Writes single digit 1 into the file, closes it and exits with status code 0 (normal exit).
    • If it does exist. Program opens the file counter.txt, reads its content and checks whether or not all the content of the file is valid integer. If it's valid integer, program increments counter by one, writes new digit into the file (replaces previous one), closes the file and exits with status code 0 (normal exit). If its not valid immediately exists with status code 1 (abnormal exit).
  5. 🚦Python🚦 In your file_system folder create file file_system_task.py. Within this file, implement program with the following behavior:
    • Upon run (with python3 file_system_task.py), program checks whether or not file counter.txt exists.
    • If its not. Program creates new file counter.txt with write/read/execute access to all users. Writes single digit 1 into the file, closes it and exits with status code 0 (normal exit).
    • If it does exist. Program opens the file counter.txt, reads its content and checks whether or not all the content of the file is valid integer. If it's valid integer, program increments counter by one, writes new digit into the file (replaces previous one), closes the file and exits with status code 0 (normal exit). If its not valid immediately exists with status code 1 (abnormal exit).
  6. In your kottans-backend repo README.md:
    • add header ## File System
    • embed the links to your secret.txt file and file_system_task source code file.
  7. You did lot already! If you honestly finished all the previous steps then go ahead and share it with others – post a message in course channel: File System — #done and add the link to your repo. This step is important, as it helps mentors to track your progress!

Extra materials

  1. 🚦Node.js🚦 Node.js docs on fs module
  2. 🚦Golang🚦 Reading files in various use cases. Golang tutorial series. No. 35.
  3. 🚦Node.js🚦 Руководство по Node.js, часть 9: работа с файловой системой
  4. 🚦Python🚦 Awesome pathlib package

Done?

➡️ Go forward to Runtime, Ecosystem and I/O

⤴️ Back to Contents