Created
May 7, 2013 19:38
-
-
Save patrick-higgins/5535484 to your computer and use it in GitHub Desktop.
Finds a rename event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns the item between startTime and endTime when oldPath was renamed to file in view. | |
// Searches file and it's folders for a rename event between those two times. | |
// Returns null if a rename event is not found. | |
private Item findRenameEventItem(View view, String oldPath, File file, long startTime, long endTime) { | |
String path = pathname(file); | |
String oldFolderName = FileUtils.getParent(oldPath, "/"); | |
String folderName = FileUtils.getParent(path, "/"); | |
String oldFileName = FileUtils.getName(oldPath, "/"); | |
// file was probably renamed during the time period | |
if (!oldFileName.equals(file.getName())) { | |
Item[] hist = file.getHistory(); | |
for (int i = 0; i < hist.length; i++) { | |
File item = (File) hist[i]; | |
long time = item.getModifiedTime().getLongValue(); | |
if (time > endTime) { | |
continue; | |
} | |
if (time < startTime) { | |
break; | |
} | |
if (i+1 < hist.length && | |
item.getName().equals(file.getName()) && | |
((File)hist[i+1]).getName().equals(oldFileName)) { | |
return item; | |
} | |
} | |
} | |
// some folder was probably renamed during the time period | |
if (!oldFolderName.equals(folderName)) { | |
while (folder != null) { | |
Item[] hist = folder.getHistory(); | |
for (int i = 0; i < hist.length; i++) { | |
Folder item = (Folder) hist[i]; | |
long time = item.getModifiedTime().getLongValue(); | |
if (time > endTime) { | |
continue; | |
} | |
if (time < startTime) { | |
break; | |
} | |
if (i+1 < hist.length && | |
!item.getName().equals(((Folder)hist[i+1]).getName())) { | |
return item; | |
} | |
} | |
folder = folder.getParentFolder(); | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a bug on line 32 where the folder member variable is used when a local variable was intended.