Seeking confirmation of a bug...

Richard Gaskin ambassador at fourthworld.com
Thu May 16 13:30:22 EDT 2019


Paul Dupuis wrote:

 > I just filed a serious bug for LC904 that is only under OSX. When
 > using 'asnwer file <prompt> with type <typelist>' the selected type is
 > supposed to be returned in 'the result'. This works as expected under
 > Windows, but under OSX using LC904 STABLE, 'the result' is the same as
 > the 'it', both contain the file path selected.
 >
 > Please see https://quality.livecode.com/show_bug.cgi?id=22070

While it will be useful to have this fixed, the current state of macOS 
should provide a mildly-tedious-but-not-difficult workaround:

The older Finder type codes (the four-character identifiers hidden away 
in the file's metadata) are long deprecated, and for more than a decade 
macOS relies on file extensions to determine type.

Since the range of type options is limited to types you set, a few 
minutes writing a function to match the file extension with the type 
categories you provided should at least get you going while waiting for 
an engine fix.

In the odd case where you may encounter a very old (or misnamed) file 
that has no type extension in its name, you could extend the function to 
see if the old Finder type is included in info provided with "the 
detailed files".

If you were super-thorough, you might even provide another check of file 
contents to confirm type.  Image formats have magic numbers, and text 
formats have patterns identifiable within a reasonably small number of 
bytes.  A short read can confirm the type of misnamed files even beyond 
what can be expected with "answer file".


Psuedocode:

   getFileNameExtension(fileName)
   if absent
      getDetailedFilesInfo
      convertFourCharTypetoExtensionString
   end if
   switch fileType
      case "png"
      case "jpg"
      case "jpeg"
         return "image"
         break
      case "text"
      case "rtf"
         return "text"
         break
    end switch
    -- bonus:
    confirmTypeByReadingSomeContent


The case block for your supported types is likely still in your code 
base.  Copying it to a new function and adding the earlier step of 
handling missing types by Finder code (if not already there) will make 
short work of this.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the Use-livecode mailing list