Skip to content

Commit 59117cc

Browse files
Fixed cyclic dependencies issues, removed code from sessions handler and started work on traversal
1 parent 50e9b44 commit 59117cc

File tree

5 files changed

+72
-14
lines changed

5 files changed

+72
-14
lines changed

internal/session/handler.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
package session
2-
3-

internal/session/manager.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import (
1010
)
1111

1212
var (
13-
activeSessions = make(map[string]*Session)
14-
activeSessionsMutex sync.RWMutex
13+
ActiveSessions = make(map[string]*Session)
14+
ActiveSessionsMutex sync.RWMutex
1515
)
1616

1717
/* for creating a session for user */
1818
func CreateSession(username string) error {
1919

20-
/* lock the activeSessions mutex till the function ends */
21-
activeSessionsMutex.Lock()
22-
defer activeSessionsMutex.Unlock()
20+
/* lock the ActiveSessions mutex till the function ends */
21+
ActiveSessionsMutex.Lock()
22+
defer ActiveSessionsMutex.Unlock()
2323

2424
/* check if session exists */
25-
if _, exists := activeSessions[username]; exists {
25+
if _, exists := ActiveSessions[username]; exists {
2626
return fmt.Errorf("user already exists in active sessions")
2727
}
2828

@@ -38,18 +38,18 @@ func CreateSession(username string) error {
3838
}
3939

4040
/* add session to active sessions */
41-
activeSessions[username] = session
41+
ActiveSessions[username] = session
4242

4343
return nil
4444
}
4545

4646
/* for expiring a session */
4747
func ExpireSession(username string) {
48-
activeSessionsMutex.Lock()
49-
defer activeSessionsMutex.Unlock()
48+
ActiveSessionsMutex.Lock()
49+
defer ActiveSessionsMutex.Unlock()
5050

5151
/* delete if user exists in active sessions */
52-
if _, exists := activeSessions[username]; exists {
53-
delete(activeSessions, username)
52+
if _, exists := ActiveSessions[username]; exists {
53+
delete(ActiveSessions, username)
5454
}
5555
}

internal/traversal/handler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package traversal
2+
3+

internal/traversal/model.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package traversal
2+
3+
/*
4+
file entry contains basic information about a file
5+
this information is displayed in the traversal view of the frontend
6+
*/
7+
type FileEntry struct {
8+
Name string `json:"name"`
9+
Path string `json:"path"`
10+
IsDir bool `json:"isDir"`
11+
Size int64 `json:"size"`
12+
ModTime int64 `json:"modTime"`
13+
}

internal/traversal/traversal.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package traversal
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
)
7+
8+
func ListFiles(path string, userID string) ([]FileEntry, error) {
9+
var entries []FileEntry
10+
11+
/* list all the files in the given directory */
12+
files, err := os.ReadDir(path)
13+
if err != nil {
14+
return nil, err
15+
}
16+
17+
/* retrive information for each file in the directory */
18+
for _, f := range files {
19+
fullPath := filepath.Join(path, f.Name())
20+
21+
/* check ACL access first */
22+
hasAccess := checkACLAccess(fullPath, userID)
23+
if !hasAccess {
24+
/* if the user doesn't have right ACL permissions for the file, skip it */
25+
continue
26+
}
27+
28+
/* get information about the file */
29+
info, err := f.Info()
30+
if err != nil {
31+
continue
32+
}
33+
34+
/* store it in entries that would be returned */
35+
entries = append(entries, FileEntry{
36+
Name: f.Name(),
37+
Path: fullPath,
38+
IsDir: f.IsDir(),
39+
Size: info.Size(),
40+
ModTime: info.ModTime().Unix(),
41+
})
42+
}
43+
44+
return entries, nil
45+
}

0 commit comments

Comments
 (0)