Folderitem.MoveTo Problem

Hello to everyone,

I’m usng folderitem.MoveTo(folderitem2) to move files from my internal harddisk to my Synology NAS. Everything works fine with files below 4 GB, but with files over 4 GB I get a hard crash.

I thought that the NAS who is connected either over SMB or AFP may not accept files over 4 GB like it’a the case for FAT 32 formated drives, but that does not seem to be the case as I can move a 6 GB file to it in the Finder.

I do also not understand why it crashes hard instead of aborting the move and generating an error message.

As always please post your exact code and the relevant part of the crashlog.

Do you test if the NAS supports files that are larger than 4 GB? Something like VolumeSupportsHugeFilesMBS?

Could that be another case of a “32bit problem in a 64bit environment” like with Xojo’s Math?

1 Like

OK, I was a way too fast. After verifying my code, I remembered that I calculate an MD5 checksum before moving files and as this process is very fast I didn’t realise that the crash already occurs here.

Here is the code I use

Public Function GetMD5Hash(f As FolderItem) as String
  // test parameters
  If f=Nil Then Return ""
  If Not f.Exists or f.IsFolder Then Return ""
  var InputData As TextInputStream
  var FileData As String
  If InputData=Nil Then
    Return ""
  End If
  Return EncodeHex(MD5(FileData))
End Function

It is the “FileData=InputData.ReadAll” (TextInputStream.ReadAll) who crashes hard if the file size exceeds 4GB

B.T.W The title of this post is no more accurate, but I don’t find a way to change it.

1 Like

OK, finally I think that String has a limit of 4 GB.

Eh, why are you reading 4 GB at once? Can you make an MD5 for like the first 100MB or does the MBS plugin have a checksum that’s working for huge files?

A checksum should be most probably a different one for different files and by reading just 100 MB this will not be the case. I initially have done this because Xojo does not offer a way to generate a checksum for a file but only for strings or memory blocks.

Nevertheless, I’ve found a workaround with a terminal wrapper for Mac OS, but it is certainly possible for windows and I will develop it later. The wrapper is also able to calculate an SHA-512, SHA-256 or SHA-1 checksum. If someone is interested in it, the code is here and it costs nothing:

Public Function getChecksum(Extends f As FolderItem, type As String) as String
  var st As String
  var term As new Shell
  #If TargetMachO or TargetARM then
    select case type
    case "SHA512"
      term.Execute"shasum -a 512 "+f.ShellPath
    case "SHA256"
      term.Execute"shasum -a 256 "+f.ShellPath
    case "SHA1"
      term.Execute"shasum -a 1 "+f.ShellPath
    case "MD5"
      term.Execute"MD5 "+f.ShellPath
    end select
    if type="MD5" then
      if st.CountFields("=")<>2 then Return ""
      Return st.NthField("=",2).Trim.Uppercase
      if st.CountFields("  ")<>2 then Return ""
      Return st.NthField("  ",1).Trim.Uppercase
    end if
  #elseif TargetWindows then
    // HAS TO BE CODED (real time test)
    // "certutil -hashfile "+f.ShellPath+" MD5"

    Return ""
End Function