how to get original path of alias file at createItem() of fileproviderextension?

Hi, I am using file provide extension to sync the app with remote storage. createItem() fileprovideer extension is calling when I copy a file and I able to sync properly with normal file and symlink files. itemTemplate.symlinkTargetPath helps me to sync symlink file.

But, I am facing the with alias file to sync. I tried to get original file name of alias file but I haven't found any option. How to get the original file name of alias file at createItem() of fileprovider extension. Is there any way to sync alias file?

My createItem() sample code at extension which sends the call to server through grpc.

public func createItem(
    basedOn itemTemplate: NSFileProviderItem,
    fields: NSFileProviderItemFields,
    contents contentsUrl: URL?,
    options: NSFileProviderCreateItemOptions = [],
    request: NSFileProviderRequest,
    progress: Progress
  ) async throws -> (NSFileProviderItem, NSFileProviderItemFields) {

    var (templateAttributes, _) = self.load(fields: fields, from: itemTemplate)

    templateAttributes.ownerAccountID = getuid();
    templateAttributes.groupOwnerAccountID = getgid();

    let identifier: NSFileProviderItemIdentifier
    let attributes: FileProviderItemAttributes
    
    if itemTemplate.contentType?.conforms(to: .directory) == true {
      // Handle folder creation
      .....
      .....
    } else if itemTemplate.contentType?.conforms(to: .symbolicLink) == true {
      // Handle symlinks
      guard let targetPath = itemTemplate.symlinkTargetPath else {
              fatalError("couldn't get symlinkTargetPath on \(itemTemplate)")
      }
      ....
      ....
    }
    else if itemTemplate.contentType?.conforms(to: .aliasFile) == true {
       // TODO I am not yet handled this case. I need to get original path of alias file.
    }
    else { 
      // Handle file creation
      ....
      ....
    }

    let item = try FileSystemItem.any(filename: itemTemplate.filename,
                                      identifier: identifier,
                                      parentIdentifier: itemTemplate.parentItemIdentifier,
                                      attributes: attributes)
 
    return (item, [])
  }

Replies

You should sync the file data inside the alias file, by reading the file at the contents URL passed as a parameter to createItem. First check the fields to be sure it contains .contents.