// Check if file has been deleted in the meantime
if (!codeFile.exists()) {
return;
}
WGFileContainer con = (WGFileContainer) db.getDocumentByDocumentKey(getDocumentKey());
if (con == null) {
WGDocumentKey docKey = new WGDocumentKey(getDocumentKey());
con = db.createFileContainer(docKey.getName());
con.save();
}
// Find new and updated files
FileObject[] filesArray = codeFile.getChildren();
if (filesArray == null) {
throw new WGDesignSyncException("Cannot collect files from directory '" + codeFile.getName().getPathDecoded() + "'. Please verify directory existence.");
}
List<FileObject> files = new ArrayList<FileObject>(Arrays.asList(filesArray));
Collections.sort(files, new FileNameComparator());
FileObject file;
Map existingFiles = new HashMap();
for (int i = 0; i < files.size(); i++) {
file = (FileObject) files.get(i);
if (isExcludedFileContainerFile(file)) {
continue;
}
ContainerFile containerFile = getContainerFile(file);
if (containerFile != null) {
if (existingFiles.containsKey(containerFile.getName())) {
// Possible in case-sensitive file systems. Another file of the same name with another case is in the dir.
continue;
}
if (file.getContent().getLastModifiedTime() != containerFile.getTimestamp()) {
doRemoveFile(con, file.getName().getBaseName());
doSaveDocument(con);
doAttachFile(con, file);
doSaveDocument(con);
containerFile.setTimestamp(file.getContent().getLastModifiedTime());
}
}
else {
containerFile = new ContainerFile(file);
if (con.hasFile(file.getName().getBaseName())) {
doRemoveFile(con, file.getName().getBaseName());
doSaveDocument(con);
}
doAttachFile(con, file);
doSaveDocument(con);
}
existingFiles.put(containerFile.getName(), containerFile);
}
// Remove deleted files from container
_files = existingFiles;
List fileNamesInContainer = WGUtils.toLowerCase(con.getFileNames());
fileNamesInContainer.removeAll(existingFiles.keySet());
Iterator deletedFiles = fileNamesInContainer.iterator();
while (deletedFiles.hasNext()) {
con.removeFile((String) deletedFiles.next());
con.save();
}
// Update metadata and save
FCMetadata metaData = (FCMetadata) readMetaData();
metaData.writeToDocument(con);
con.save();
FileObject metadataFile = getMetadataFile();
if (metadataFile.exists()) {
_timestampOfMetadataFile = metadataFile.getContent().getLastModifiedTime();
}