1

I created an app that compile Swift scripts or projects from server side, shows the output, and then the app downloads the executable file.

I know I can't directly run this file, but I can do that from server side, so in my app's file explorer, it should be able to show a custom file icon if the file is executable. When the app downloads the file, this code is ran:

do {
    let attributes: [FileAttributeKey:AnyObject] = [FileAttributeKey.posixPermissions: NSNumber(value: 0o775 as UInt16)]
    try FileManager.default.setAttributes(attributes, ofItemAtPath: MY_FILE_PATH)
} catch let error {
    print(error.localizedDescription)
}

This is the code to check if the file is executable:

print("Is the file executable?")
if FileManager.default.isExecutableFile(atPath: url.path) { // Is executable
    image.image = #imageLiteral(resourceName: "Exe")
    print("YES")
}

But in the file explorer, the file icon is not the executable icon and there is no error setting file attributes.

So my question is, when FileManager.default.isExecutableFile returns true?

It's from file permissions or from architecture (the file is compiled for a Raspberry Pi and not for iOS) ?

Emma Labbé
  • 667
  • 7
  • 18
  • 1
    "the file is compiled for a Raspberry Pi" So why would iOS _ever_ see this as an "executable"? – matt May 03 '17 at 20:05
  • @matt I thought that was such as Unix, by permission, because the file has executable permissions – Emma Labbé May 03 '17 at 20:08
  • But since the docs explicitly say "Returns a Boolean value that indicates whether the operating system appears able to execute a specified file", and since _you_ say that _this_ operating system will _not_ be able to execute this file, why on earth would you ever expect this to return `true` for this file? – matt May 03 '17 at 20:11
  • Since you explicitly say that this is about the file's executable permissions, what I would recommend is that you ask the file manager to fetch the file's permissions, and look at them: https://developer.apple.com/reference/foundation/fileattributekey/1418260-posixpermissions I don't actually know what that will do for this file, but surely it's more of a snowball's chance in Hades than what you _were_ doing. – matt May 03 '17 at 20:13
  • I'll be curious to know what happens! – matt May 03 '17 at 20:15
  • You say that your app "downloads the file", therefore I assume that your app is creating the file on the iOS device; it is therefore up to your app to set the file permissions as it needs; iOS, just like Unix, doesn't implicitly set the execute bit when you create a file. An explicit operation is required to set that bit. Permissions are metadata, so it sounds like you need to explicitly query the permissions of the files on your server and ensure that this is replicated/shown in your app somehow. – Paulw11 May 03 '17 at 20:38
  • @Paulw11 Yes, I set permissions when the file is downloaded – Emma Labbé May 03 '17 at 20:40
  • Answer to the Q you deleted. ` func textExceedBoundsOf(_ textView: UITextView) -> Bool { let textHeight = textView.contentSize.height return textHeight > self.textView.bounds.height } ` – Adrian May 27 '17 at 03:13
  • @Adrian thank you so very much, is just what I need – Emma Labbé May 27 '17 at 03:14
  • This is a little easier to read. https://stackoverflow.com/a/44212591/4475605 – Adrian May 27 '17 at 03:19

0 Answers0