Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oblig3-myFS
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ii
INF113
24H
Oblig3-myFS
Commits
73ba3cb9
Commit
73ba3cb9
authored
5 months ago
by
David Grellscheid
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup some lines after discord comments
parent
45885251
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+18
-16
18 additions, 16 deletions
main.py
myfs.py
+3
-3
3 additions, 3 deletions
myfs.py
with
21 additions
and
19 deletions
main.py
+
18
−
16
View file @
73ba3cb9
...
...
@@ -25,23 +25,26 @@ it, 'and what is the use of a book,' thought Alice 'without pictures or
conversations?
'
"""
test_sample
=
"
Did you know that the moon is made of cheese?
"
test_sample
=
"
Did you know that the moon is made of cheese?
\0\0\0
"
def
test_1
():
with
open
(
"
test1.fs
"
,
'
r
+b
'
)
as
f
:
with
open
(
"
test1.fs
"
,
'
w
+b
'
)
as
f
:
format
(
f
)
# clear the file system
try
:
for
i
in
range
(
7
):
# Add 7 files (is max with the original capacity)
save
(
f
,
f
"
alice
{
i
}
.txt
"
,
f
"
content
{
i
}
"
)
# Remove 1 file, there should be more space now
remove
(
f
,
f
"
alice
{
i
}
.txt
"
)
# try adding another file
save
(
f
,
f
"
hello.txt
"
,
f
"
Hello World!
"
)
# Check that the new file is there
assert
load
(
f
,
"
hello.txt
"
)
==
"
Hello World!
"
# Remove 1 file, there should be more space now
remove
(
f
,
"
alice3.txt
"
)
# try adding another file
save
(
f
,
"
hello.txt
"
,
"
Hello World!
"
)
# Check that the new file is there
content
=
load
(
f
,
"
hello.txt
"
)
except
Exception
as
e
:
print
(
f
"
Test 1 failed:
{
e
}
"
)
content
=
""
assert
content
==
"
Hello World!
"
def
test_2
():
...
...
@@ -50,7 +53,6 @@ def test_2():
format
(
f
)
save
(
f
,
"
test.txt
"
,
test_sample
)
content
=
load
(
f
,
"
test.txt
"
)
content
=
content
.
decode
(
'
utf-8
'
)
assert
content
==
test_sample
...
...
@@ -58,13 +60,15 @@ def test_3():
# test that block was not zeroed out when deleted
with
open
(
"
test_remove_not_zeroed_out.fs
"
,
'
w+b
'
)
as
f
:
format
(
f
)
f
.
seek
(
0
)
clean_state
=
f
.
read
()
save
(
f
,
"
test.txt
"
,
test_sample
)
remove
(
f
,
"
test.txt
"
)
# Check that the file system is not fully zeroed out
f
.
seek
(
0
)
content
=
f
.
read
()
assert
any
(
byte
!=
0
for
byte
in
content
)
,
"
File system is fully zeroed out after removal
"
assert
content
!=
clean_state
,
"
File system is fully zeroed out after removal
. It should not be
"
def
test_4
():
...
...
@@ -76,13 +80,11 @@ def test_4():
# Test that the content is the same
content
=
load
(
f
,
"
link.txt
"
)
content
=
content
.
decode
(
'
utf-8
'
)
assert
content
==
test_sample
# Test that removing the original file does not affect the hard link
remove
(
f
,
"
test.txt
"
)
content
=
load
(
f
,
"
link.txt
"
)
content
=
content
.
decode
(
'
utf-8
'
)
assert
content
==
test_sample
# test that the file can be removed
...
...
@@ -100,7 +102,7 @@ print(f"* Use xxd {backingfile} to inspect contents")
print
(
"
*
"
*
60
)
print
()
#test_1()
#test_2()
#test_3()
#test_4()
#
test_1()
#
test_2()
#
test_3()
#
test_4()
This diff is collapsed.
Click to expand it.
myfs.py
+
3
−
3
View file @
73ba3cb9
...
...
@@ -59,11 +59,11 @@ def _set_num_files(f, n):
def
_get_num_linked_files
(
f
):
...
# Oppgave 4
pass
# Oppgave 4
def
_set_num_linked_files
(
f
,
n
):
...
# Oppgave 4
pass
# Oppgave 4
...
...
@@ -193,4 +193,4 @@ def hard_link(f, existing_file, link_name):
link_name (str): The name of the new hard link.
"""
#TODO: implement this function
...
pass
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment