-
Notifications
You must be signed in to change notification settings - Fork 25
tee #42
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
base: main
Are you sure you want to change the base?
tee #42
Conversation
|
I will code review this |
|
After make qemu, the test folder shows up in the listing. "tee [file]" works in creating a file (not only limited to text files, but that was not part of the description, so it's alright for the program to do that.) When using "tee -a [file]" and the "tee [file]", after writing a line to qemu, it is printed back, and the user might think they have written to the file twice. NOTE: When running "cat" on the recently appended file, it shows only the number of lines that the user entered. I suggest removing the confusion by removing the output line that prints the line the user just typed in. Additionally, you can also output the contents of the file first when opening it with append mode to help the user understand what contents are already in the file. Additionally, "tee -a [file]" when used with a file that did not exist does not return an error but instead creates the file and writes to it. It works for writing error messages as well. The code formatting is generally consistent and follows the style of the other user-space utilities in the project. There are no major formatting issues to address. Good Job! High Level Checks: Code Checks: |
|
✅ PR fully resolves the task/issue ✅ Does the code achieve its intended purpose? Your tests and walkthrough are clear, concise, and easy to follow. Running the provided commands worked as expected. Your code is clean, well-documented, and easy to understand. Variable names and comments are clear, and formatting is consistent throughout. The code correctly initializes fds for up to 10 files, so the 7-file cap isn’t caused by your implementation. After checking, it seems to stem from the MAXARGS definition (set to 10) in sh.c. Adjusting that constant would allow handling all 10 files. So this isn’t an error in your PR, just a shell-level limit worth noting. Summary: |
|
Verification The goals you described in the issue is exactly what this pull request fulfills! The tee command and -a flag work as they are supposed to as according to your documentation. No functionality missing! Testing The test folder and walkthrough you provided are very clear and concise. It is easy to follow along and understand what is expected when running a command and it's usage. I did find the Squidward drawing by doing tee -a amazing! But proves that your test cases work as you provided some and other various examples. I did however run into an interesting detail that will be mentioned in the code walkthrough as well... When running cat and piping that output as the input for tee, you can only write up to 7 files. It's not the 10 from earlier documentation, however if we remove 'cat' and piping and solely do 'tee test1.txt {...}' we can then write up to 8 files. Small issue but it works as expected. Code Walkthrough Code wise, documentation, comments, variable names are all good. It's easy to read your code and to understand what is happening. I would make some change to the code error logic but it's me being a nitpick since I worry about errors a lot. You wrote: fds[i - file_start] = open(argv[i], flags); But then after you check if 'i - file_start < 0' as a check, I personally would put the condition first to see if we should attempt our open() or to print an error otherwise. It's not anything major and as I said me being too picky. As for the error when writing up to 7 files or 8 files, on my initial look, I thought perhaps you handled arguments in a different way but you did initialize fds to 10, so that's correct. You also don't handle or affect other areas of the code, but I did look in sh.c and there is a MAXARGS definition set to 10. So code wise if you wanted to get your '10 files at once' to work, this may need to be changed. But, I think it's good to note the only 'error' presented by your code isn't your fault! Formatting was consistent. Everything looks really good. Amazing work! High Level Checks:
Code Checks:
|
|
Looks great! Tee is a fun utility. Cool project. Here's what I found:
4.5/5 |
FogOS tee
Build
make clean
make
make qemu
After running these commands, run
lsto make sure thetestsdirectory is listed so you can run the tests below!Purpose
teereads from standard input and writes it to both standard output and up to 10 files at a time.The command
tee [file]will read from standard input and write the contents of what was just added to both the standard output and the specified file. If the file does not exist, it will be created. If it does exist, it will be overwritten by default.The -a flag can be used as well. When
tee -a [file]is used, it will append the input to the end of the given file(s), without overwriting it.ctrl+dis pressed.If you would like to see if it worked, use the cat command!
Examples
Check the results using
cat [file]Creates a file
test.txtand reads from standard input. Once you pressenterandctrl+d, what you wrote is written to the terminal and to the file!test.txtcat test.txtAppends to
test.txtusing the -a flag.test.txtcat test.txtUsing
echoto add Hello to file1.txtfile1.txtcat file1.txtCopying the contents of
test.txtintocopied.txttest.txtwill be printed to the terminal and written into the newly created filetest.txtcat copied.txtUsing the test files, if you append
sqd_btm.txttosqd_top.txthit enter andcat tests/sqd_top.txtyou will get an ASCII drawing of squidward!tests/sqd_btm.txtwill be printed to the terminal and appended to the existing filetests/sqd_top.txtcat tests/sqd_top.txtThis examples demonstrates appending to multiple files. It appends the first fish ascii art into the other 2 fish files.
tests/fish.txtwill be printed to the terminal and appended to the existing filescat tests/fish1.txt&cat tests/fish2.txtThis shows a more useful way to use this command. If you would like to pull out any error messages from one file and put it in another file, you can! In this case,
grepsearches for the wordTheinbrwn_fox.txtand prints out and writes the lines that containThetofind.txt.find.txtcat find.txtHere is another one! For this example, all the lines that include
can'tingingerb.txtis appended to thefind.txtthat was created above.find.txtcat find.txt