readPermissionFileList function

Future<Map<String, dynamic>> readPermissionFileList({
  1. required List<String> fileList,
  2. bool isFile = true,
  3. bool isFilePath = false,
  4. bool isFileUrl = false,
})

Read permissions of each file in a list of files, Note: the list of files are always files owned by the user.

Parameters:

  • fileList - is the list of files in the user's Pod.
  • isFile - flag describing whether the resource is a file, false if the resource is a directory. (Default: true).
  • isFilePath - Flag describing whether the filenames provided as keys in the dataMap provide the filename with the app data dir. (Default: false).
  • isFileUrl - Flag describing whether filenames used as keys in dataMap are the url of the file. (Default: false).

Implementation

Future<Map<String, dynamic>> readPermissionFileList({
  required List<String> fileList,
  bool isFile = true,
  bool isFilePath = false,
  bool isFileUrl = false,
}) async {
  // Initialise data map to hold returned permission of each file
  Map<String, dynamic> dataMap = <String, dynamic>{};
  List<Future<dynamic>> futures = [];

  // Create a list of future functions
  for (final fileName in fileList) {
    futures.add(
      readPermission(fileName: fileName, isFile: isFile, isFileUrl: isFileUrl),
    );
  }

  // Wait for permission list futures synchronously
  List<dynamic> results = await Future.wait(futures);

  // Add returned permission lists to data map
  for (int i = 0; i < fileList.length; i++) {
    // Add fileName key
    dataMap[fileList[i]] = {};

    // Add permission list
    dataMap[fileList[i]][authUserPred] = results[i];
  }

  return dataMap;
}