public static SyncFile updateFolderSyncFile(Path filePath, long syncAccountId, SyncFile syncFile)
      throws Exception {

    // Local sync file

    updateSyncFile(filePath, syncFile.getParentFolderId(), syncFile);

    // Remote sync file

    if ((syncFile.getState() != SyncFile.STATE_ERROR)
        && (syncFile.getState() != SyncFile.STATE_UNSYNCED)) {

      FileEventUtil.updateFolder(filePath, syncAccountId, syncFile);
    }

    return syncFile;
  }
  @Test
  public void testDoUpdateFolderSyncFile() throws Exception {
    SyncFile folderSyncFileA =
        SyncFileTestUtil.addFolderSyncFile(
            FileUtil.getFilePathName(filePathName, "a"), syncAccount.getSyncAccountId());

    SyncFile folderSyncFileB =
        SyncFileTestUtil.addFolderSyncFile(
            FileUtil.getFilePathName(filePathName, "b"), syncAccount.getSyncAccountId());

    SyncFile folderSyncFileAA =
        SyncFileTestUtil.addFolderSyncFile(
            FileUtil.getFilePathName(filePathName, "a", "a"),
            folderSyncFileA.getTypePK(),
            syncAccount.getSyncAccountId());

    SyncFile fileSyncFileAA =
        SyncFileTestUtil.addFileSyncFile(
            FileUtil.getFilePathName(filePathName, "a", "a.txt"),
            folderSyncFileA.getTypePK(),
            syncAccount.getSyncAccountId());

    SyncFileService.updateSyncFile(
        Paths.get(FileUtil.getFilePathName(filePathName, "b", "a")),
        folderSyncFileB.getTypePK(),
        folderSyncFileA);

    SyncFilePersistence syncFilePersistence = SyncFileService.getSyncFilePersistence();

    folderSyncFileAA = syncFilePersistence.queryForId(folderSyncFileAA.getTypePK());

    Assert.assertEquals(
        FileUtil.getFilePathName(filePathName, "b", "a", "a"), folderSyncFileAA.getFilePathName());

    fileSyncFileAA = syncFilePersistence.queryForId(fileSyncFileAA.getTypePK());

    Assert.assertEquals(
        FileUtil.getFilePathName(filePathName, "b", "a", "a.txt"),
        fileSyncFileAA.getFilePathName());
  }
  public static SyncFile moveFolderSyncFile(
      Path filePath, long parentFolderId, long syncAccountId, SyncFile syncFile) throws Exception {

    // Local sync file

    SyncFile targetSyncFile = fetchSyncFile(filePath.toString());

    if (targetSyncFile != null) {
      deleteSyncFile(targetSyncFile, false);
    }

    updateSyncFile(filePath, parentFolderId, syncFile);

    // Remote sync file

    if ((syncFile.getState() != SyncFile.STATE_ERROR)
        && (syncFile.getState() != SyncFile.STATE_UNSYNCED)) {

      FileEventUtil.moveFolder(parentFolderId, syncAccountId, syncFile);
    }

    return syncFile;
  }