Conversation
Signed-off-by: Ben <ben@armosec.io>
Signed-off-by: Ben <ben@armosec.io>
slashben
commented
Jul 23, 2023
Comment on lines
+150
to
+208
| // Normalize the bucket name | ||
| container = NormalizeBucketName(container) | ||
|
|
||
| // Create a map of string to bool | ||
| fileList := make(map[string]bool) | ||
| // Check if bucket exists in the map | ||
| f.Lock.Lock() | ||
| fileObject, ok := f.fileMap[container] | ||
| if !ok { | ||
| f.Lock.Unlock() | ||
| return fileList, fmt.Errorf("bucket does not exist for container %s", container) | ||
| } | ||
| f.Lock.Unlock() | ||
|
|
||
| // Lock the file | ||
| fileObject.Lock.Lock() | ||
| // Close the file | ||
| fileObject.FileObject.Close() | ||
|
|
||
| // Do not use defer here! It makes life much harder | ||
|
|
||
| // Copy the file to a new file | ||
| storageFileName := fmt.Sprintf("%s/%s.txt", f.dirPath, container) | ||
| storageFileCopyName := fmt.Sprintf("%s/%s_copy.txt", f.dirPath, container) | ||
| // Copy the file | ||
| err := copyFile(storageFileName, storageFileCopyName) | ||
| if err != nil { | ||
| fileObject.FileObject, _ = os.OpenFile(storageFileName, os.O_CREATE|os.O_WRONLY, 0644) | ||
| fileObject.Lock.Unlock() | ||
| return fileList, err | ||
| } | ||
|
|
||
| // Open the file | ||
| fileObject.FileObject, err = os.OpenFile(storageFileName, os.O_CREATE|os.O_WRONLY, 0644) | ||
| if err != nil { | ||
| fileObject.Lock.Unlock() | ||
| return fileList, err | ||
| } | ||
| fileObject.Writer = bufio.NewWriter(fileObject.FileObject) | ||
|
|
||
| // Unlock the file and let other goroutines use it | ||
| fileObject.Lock.Unlock() | ||
|
|
||
| // Read the file line by line | ||
| file, err := os.Open(storageFileCopyName) | ||
| if err != nil { | ||
| return fileList, err | ||
| } | ||
| defer file.Close() | ||
| defer os.Remove(storageFileCopyName) | ||
| scanner := bufio.NewScanner(file) | ||
| for scanner.Scan() { | ||
| fileList[scanner.Text()] = true | ||
| } | ||
| if err := scanner.Err(); err != nil { | ||
| return fileList, err | ||
| } | ||
| return fileList, nil | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Need to protect this as per bucket against re-entrancy (there is a single "copy" file that can be overwritten)
Signed-off-by: Ben <ben@armosec.io>
|
Summary:
|
added 2 commits
July 23, 2023 20:50
|
Summary:
|
Signed-off-by: Ben <ben@armosec.io>
|
Summary:
|
|
Summary:
|
|
Summary:
|
Signed-off-by: Ben <ben@armosec.io>
|
Summary:
|
Signed-off-by: Ben <ben@armosec.io>
|
Summary:
|
Signed-off-by: Ben <ben@armosec.io>
|
Summary:
|
|
We have decided to move forward with the in-memory storage. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview