Giter VIP home page Giter VIP logo

Comments (7)

onevcat avatar onevcat commented on May 23, 2024 2

+1 for eliminating the extension verifying. It is not necessary or a good reason to use the extension to determine whether the file can be opened or not. My situation is similar to @jwelton 's: a downloaded file by URLSession gives a tmp extension for now. I can add tmp to the allowed list, but there is no guarantee the downloaded file would be always end with tmp. Manually adding zip suffix to the file name is quite unnature for an elegant API.

from zip.

yvbeek avatar yvbeek commented on May 23, 2024 1

Is it necessary to check if the file exists? Apple, in their documentation, recommends to try to open the file and to handle any errors that might occur gracefully.

NOTE
Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. Itโ€™s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file-system race conditions, see Race Conditions and Secure File Operations in Secure Coding Guide.

Source: NSFileManager fileExistsAtPath(_:)

from zip.

jwelton avatar jwelton commented on May 23, 2024

From what I understand, this will not be easy to implement. The NSFileManager does not recognize files that do not have an extension. (I've tried this and I'm getting false from fileExistsAtPath, when the file does exist). Perhaps your solution would be to explicitly set the extension, like you mentioned.

from zip.

jwelton avatar jwelton commented on May 23, 2024

This is true, however when bypassing validation, the following line was failing:
try fileManager.attributesOfItemAtPath(path)

from zip.

yvbeek avatar yvbeek commented on May 23, 2024

In my test it doesn't seem to fail. Am I missing something?

Test file /tmp/test0, created with:

mkfile -n 5m /tmp/test0

Swift code:

let fileManager = NSFileManager.defaultManager()
let attributes = try? fileManager.attributesOfItemAtPath("/tmp/test0")
print(attributes)

Output:

Optional([
  "NSFileCreationDate": 2016-08-03 01:31:10 +0000, 
  "NSFileGroupOwnerAccountName": wheel, 
  "NSFileExtensionHidden": 0, 
  "NSFileSize": 5242880, 
  "NSFileGroupOwnerAccountID": 0, 
  "NSFileOwnerAccountID": 501, 
  "NSFilePosixPermissions": 384,
  "NSFileType": NSFileTypeRegular, 
  "NSFileSystemFileNumber": 39560369, 
  "NSFileSystemNumber": 16777220, 
  "NSFileReferenceCount": 1, 
  "NSFileModificationDate": 2016-08-03 01:31:10 +0000
])

File size, creation and modification date etc. all seem to make sense.
It also works fine if the file without extension is in the app document directory.

from zip.

PierreMardon avatar PierreMardon commented on May 23, 2024

Just to let you know, I use your project and it's working well but having to add .zip is unnatural.
There are multiple other file formats using zip compression, in my case mxl : http://www.musicxml.com/tutorial/compressed-mxl-files/

from zip.

awulf avatar awulf commented on May 23, 2024

Tried the code by removing the validation, and has no issues with other extensions. Also this validation is case sensitive so if you need to add all the combinations zip Zip ZIP etc making it extra annoying if you need to add others too.

from zip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.