Skip to content

fix: Issue #631 raise an error when trying to extract a file (.zip_)#636

Merged
yorukot merged 5 commits into
yorukot:mainfrom
WarrenU:fix-issues-631
Mar 2, 2025
Merged

fix: Issue #631 raise an error when trying to extract a file (.zip_)#636
yorukot merged 5 commits into
yorukot:mainfrom
WarrenU:fix-issues-631

Conversation

@WarrenU

@WarrenU WarrenU commented Feb 20, 2025

Copy link
Copy Markdown
Contributor

Addresses issue #631 Unzipping a malformed/invalid zip file by raising an error if the extension is wrong.

  • Added isExensionExtractable function to check against file types we can extract from the xtractr package. (return bool if we can extract or not)
  • Removed internal unzip function, as xtractr can handle unzipping zip file.
  • example log: time=2025-02-21T10:53:00.459-08:00 level=ERROR msg="Error unexpected file extension type: .zip_" error="unsupported operation"

Trial screenshot below (No progress in bottom left as also mentioned in issue):
image

❓ This is my first PR and I'm a brand new beginner to superfile.
Where would I see these logged errors? I ran it with VScode and put some breakpoints in to ensure the code I was hitting was working as expected. And it made some __debug_bin3073481771.exe files. I'm running it on windows. But not sure how to introspect that file or where to see the errors.

…e) a file that does not have a valid extension
@netlify

netlify Bot commented Feb 20, 2025

Copy link
Copy Markdown

Deploy Preview for superfile canceled.

Name Link
🔨 Latest commit 2428670
🔍 Latest deploy log https://app.netlify.com/sites/superfile/deploys/67c04712d8b1f600080bc7bf

@jachewz

jachewz commented Feb 21, 2025

Copy link
Copy Markdown
Contributor

sort of related but is it a good idea to remove the ".zip" case since extractCompressFile() can handle".zip" files as well?

switch ext {
case ".zip":
err = unzip(panel.element[panel.cursor].location, outputDir)
if err != nil {
slog.Error("Error extract file", "error", err)
return
}
default:
err = extractCompressFile(panel.element[panel.cursor].location, outputDir)
if err != nil {
outPutLog("Error extract file", "error", err)
return
}
}
}

Reduces the need to maintain the in-house unzip() function.

@lazysegtree

lazysegtree commented Feb 21, 2025

Copy link
Copy Markdown
Collaborator

@WarrenU slog.Error goes to superfile log file whose location you can see by running spf path-list .

See - https://superfile.netlify.app/configure/config-file-path/
And set debug = true in config file to also see debug logs.

Comment thread src/internal/string_function.go Outdated

// isValidFileExtension checks if a string is a valid file extension.
// Returns nil if valid, otherwise returns an error with a descriptive message.
func isValidFileExtension(ext string) error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should return a bool, not an error.
error denotes failures in execution. If you give an invalid extension to this function, it successfully detects that its invalid, and return false. There is no error.

Comment thread src/internal/handle_file_operations.go Outdated
var err error
panel := &m.fileModel.filePanels[m.filePanelFocusIndex]
ext := strings.ToLower(filepath.Ext(panel.element[panel.cursor].location))
err = isValidFileExtension(ext)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont wanna check if the extension is valid, but if it can be extracted or not. I dont think .jpg can be extracted. We should replace this with isExensionExtractable and just check for a few supported extenstions .zip, .tar.gz, .rar whichever we support.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to isExensionExtractable that makes sense and I agree.

@lazysegtree

Copy link
Copy Markdown
Collaborator

sort of related but is it a good idea to remove the ".zip" case since extractCompressFile() can handle".zip" files as well?

@jachewz If it can handle, then we should remove it. Then we dont need the unzip function and we can delete that .

@WarrenU

WarrenU commented Feb 21, 2025

Copy link
Copy Markdown
Contributor Author

sort of related but is it a good idea to remove the ".zip" case since extractCompressFile() can handle".zip" files as well?

@jachewz If it can handle, then we should remove it. Then we dont need the unzip function and we can delete that .

I removed the unzip, and opted to use xtractr default. I also added an explicit slog call for any error it raises.

Good mention @jachewz

@lazysegtree

lazysegtree commented Feb 21, 2025

Copy link
Copy Markdown
Collaborator

I would like us a to do a bit of testing that it can handle .tar.gz , .rar and most of these extensions. I will try to test it out sometimes. It would be great if @WarrenU you could also perform some of the tests.

@WarrenU

WarrenU commented Feb 25, 2025

Copy link
Copy Markdown
Contributor Author

.rar, .tar.gz, .zip are working. ✅

@yorukot

yorukot commented Feb 27, 2025

Copy link
Copy Markdown
Owner

I just discovered during testing that if there is a directory in the decompression, permission denied will occur, so I added:

x := &xtractr.XFile{
	FilePath:  src,
	OutputDir: dest,
+	FileMode:  0644,
+	DirMode:   0755,
}

Now it seems that it can be merge.

Btw The reason why I separated the zip is actually because I want to allow users to see the real-time progress.But it is fine to remove it.

@yorukot yorukot merged commit fbb4056 into yorukot:main Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants