Lines 15-22
Link Here
|
15 |
import java.net.URI; |
15 |
import java.net.URI; |
16 |
import java.util.*; |
16 |
import java.util.*; |
17 |
|
17 |
|
18 |
import org.eclipse.core.filesystem.EFS; |
18 |
import org.eclipse.core.filesystem.*; |
19 |
import org.eclipse.core.filesystem.IFileStore; |
|
|
20 |
import org.eclipse.core.resources.*; |
19 |
import org.eclipse.core.resources.*; |
21 |
import org.eclipse.core.runtime.*; |
20 |
import org.eclipse.core.runtime.*; |
22 |
import org.eclipse.osgi.util.NLS; |
21 |
import org.eclipse.osgi.util.NLS; |
Lines 72-83
Link Here
|
72 |
return null; |
71 |
return null; |
73 |
} |
72 |
} |
74 |
|
73 |
|
|
|
74 |
// process Entries file contents |
75 |
String[] entries = readLines(cvsSubDir.getFile(ENTRIES)); |
76 |
String[] entriesLog = readLines(cvsSubDir.getFile(ENTRIES_LOG)); |
77 |
return readAllResourceSync(parent.getFullPath().toOSString(), entries, entriesLog); |
78 |
} |
79 |
|
80 |
/** |
81 |
* Reads the CVS/Entries, CVS/Entries.log and CVS/Permissions files from the |
82 |
* specified folder and returns ResourceSyncInfo instances for the data stored therein. |
83 |
* If the folder does not have a CVS subdirectory then <code>null</code> is returned. |
84 |
*/ |
85 |
private static byte[][] readAllResourceSync(String userPath, String[] entries, String[] entriesLog) throws CVSException { |
75 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
86 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
76 |
System.out.println("Reading Entries file for " + parent.getFullPath()); //$NON-NLS-1$ |
87 |
System.out.println("Reading Entries file for " + userPath); //$NON-NLS-1$ |
77 |
} |
88 |
} |
78 |
|
89 |
|
79 |
// process Entries file contents |
90 |
// process Entries file contents |
80 |
String[] entries = readLines(cvsSubDir.getFile(ENTRIES)); |
|
|
81 |
if (entries == null) return null; |
91 |
if (entries == null) return null; |
82 |
Map infos = new TreeMap(); |
92 |
Map infos = new TreeMap(); |
83 |
for (int i = 0; i < entries.length; i++) { |
93 |
for (int i = 0; i < entries.length; i++) { |
Lines 89-101
Link Here
|
89 |
} catch (CVSException e) { |
99 |
} catch (CVSException e) { |
90 |
// There was a problem parsing the entry line. |
100 |
// There was a problem parsing the entry line. |
91 |
// Log the problem and skip the entry |
101 |
// Log the problem and skip the entry |
92 |
CVSProviderPlugin.log(new CVSStatus(IStatus.ERROR, NLS.bind(CVSMessages.SyncFileWriter_0, new String[] { parent.getFullPath().toString() }), e)); |
102 |
CVSProviderPlugin.log(new CVSStatus(IStatus.ERROR, NLS.bind(CVSMessages.SyncFileWriter_0, new String[] { userPath }), e)); |
93 |
} |
103 |
} |
94 |
} |
104 |
} |
95 |
} |
105 |
} |
96 |
|
106 |
|
97 |
// process Entries.log file contents |
107 |
// process Entries.log file contents |
98 |
String[] entriesLog = readLines(cvsSubDir.getFile(ENTRIES_LOG)); |
|
|
99 |
if (entriesLog != null) { |
108 |
if (entriesLog != null) { |
100 |
for (int i = 0; i < entriesLog.length; i++) { |
109 |
for (int i = 0; i < entriesLog.length; i++) { |
101 |
String line = entriesLog[i]; |
110 |
String line = entriesLog[i]; |
Lines 121-126
Link Here
|
121 |
return result; |
130 |
return result; |
122 |
} |
131 |
} |
123 |
|
132 |
|
|
|
133 |
public static byte[][] readAllResourceSync(IPath parent) throws CVSException { |
134 |
IPath cvsSubDir = getCVSSubdirectory(parent); |
135 |
|
136 |
if (!cvsSubDir.toFile().exists()){ |
137 |
return null; |
138 |
} |
139 |
|
140 |
// process Entries file contents |
141 |
String[] entries = readLines(cvsSubDir.append(ENTRIES)); |
142 |
// process Entries.log file contents |
143 |
String[] entriesLog = readLines(cvsSubDir.append(ENTRIES_LOG)); |
144 |
return readAllResourceSync(parent.toOSString(), entries, entriesLog); |
145 |
} |
146 |
|
124 |
private static boolean folderExists(IFolder cvsSubDir) throws CVSException { |
147 |
private static boolean folderExists(IFolder cvsSubDir) throws CVSException { |
125 |
try { |
148 |
try { |
126 |
URI uri = cvsSubDir.getLocationURI(); |
149 |
URI uri = cvsSubDir.getLocationURI(); |
Lines 136-141
Link Here
|
136 |
return false; |
159 |
return false; |
137 |
} |
160 |
} |
138 |
|
161 |
|
|
|
162 |
private static boolean folderExists(IPath cvsSubDir) throws CVSException { |
163 |
return cvsSubDir.toFile().exists(); |
164 |
} |
165 |
|
139 |
public static void writeAllResourceSync(IContainer parent, byte[][] infos) throws CVSException { |
166 |
public static void writeAllResourceSync(IContainer parent, byte[][] infos) throws CVSException { |
140 |
try { |
167 |
try { |
141 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
168 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
Lines 159-164
Link Here
|
159 |
throw CVSException.wrapException(e); |
186 |
throw CVSException.wrapException(e); |
160 |
} |
187 |
} |
161 |
} |
188 |
} |
|
|
189 |
|
190 |
public static void writeAllResourceSync(IPath parent, byte[][] infos) throws CVSException { |
191 |
try { |
192 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
193 |
System.out.println("Writing Entries file for folder " + parent.toOSString()); //$NON-NLS-1$ |
194 |
} |
195 |
IPath cvsSubDir = getCVSSubdirectory(parent); |
196 |
if (!cvsSubDir.toFile().exists()) { |
197 |
cvsSubDir.toFile().mkdir(); |
198 |
} |
199 |
|
200 |
// format file contents |
201 |
String[] entries = new String[infos.length]; |
202 |
for (int i = 0; i < infos.length; i++) { |
203 |
byte[] info = infos[i]; |
204 |
entries[i] = new String(info); |
205 |
} |
206 |
|
207 |
// write Entries |
208 |
writeLines(cvsSubDir.append(ENTRIES), entries); |
209 |
|
210 |
// delete Entries.log |
211 |
cvsSubDir.append(ENTRIES_LOG).toFile().delete(); |
212 |
} catch(IOException e) { |
213 |
throw CVSException.wrapException(e); |
214 |
} |
215 |
} |
216 |
|
162 |
/** |
217 |
/** |
163 |
* Reads the CVS/Root, CVS/Repository, CVS/Tag, and CVS/Entries.static files from |
218 |
* Reads the CVS/Root, CVS/Repository, CVS/Tag, and CVS/Entries.static files from |
164 |
* the specified folder and returns a FolderSyncInfo instance for the data stored therein. |
219 |
* the specified folder and returns a FolderSyncInfo instance for the data stored therein. |
Lines 211-216
Link Here
|
211 |
} |
266 |
} |
212 |
|
267 |
|
213 |
/** |
268 |
/** |
|
|
269 |
* Reads the CVS/Root, CVS/Repository, CVS/Tag, and CVS/Entries.static files from |
270 |
* the specified folder and returns a FolderSyncInfo instance for the data stored therein. |
271 |
* If the folder does not have a CVS subdirectory then <code>null</code> is returned. |
272 |
*/ |
273 |
public static FolderSyncInfo readFolderSync(IPath folder) throws CVSException { |
274 |
IPath cvsSubDir = getCVSSubdirectory(folder); |
275 |
|
276 |
if (!folderExists(cvsSubDir)){ |
277 |
return null; |
278 |
} |
279 |
|
280 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
281 |
System.out.println("Reading Root/Repository files for " + folder.toOSString()); //$NON-NLS-1$ |
282 |
} |
283 |
|
284 |
// read CVS/Root |
285 |
String root = readFirstLine(cvsSubDir.append(ROOT)); |
286 |
if (root == null) return null; |
287 |
|
288 |
// read CVS/Repository |
289 |
String repository = readFirstLine(cvsSubDir.append(REPOSITORY)); |
290 |
if (repository == null) return null; |
291 |
|
292 |
// read CVS/Tag |
293 |
String tag = readFirstLine(cvsSubDir.append(TAG)); |
294 |
if (Policy.DEBUG_METAFILE_CHANGES && tag != null) { |
295 |
System.out.println("Reading Tag file for " + folder.toOSString()); //$NON-NLS-1$ |
296 |
} |
297 |
CVSTag cvsTag = (tag != null) ? new CVSEntryLineTag(tag) : null; |
298 |
|
299 |
// read Entries.Static |
300 |
String staticDir = readFirstLine(cvsSubDir.append(STATIC)); |
301 |
if (Policy.DEBUG_METAFILE_CHANGES && staticDir != null) { |
302 |
System.out.println("Reading Static file for " + folder.toOSString()); //$NON-NLS-1$ |
303 |
} |
304 |
boolean isStatic = (staticDir != null); |
305 |
|
306 |
// return folder sync |
307 |
return new FolderSyncInfo(repository, root, cvsTag, isStatic); |
308 |
} |
309 |
|
310 |
/** |
214 |
* Writes the CVS/Root, CVS/Repository, CVS/Tag, and CVS/Entries.static files to the |
311 |
* Writes the CVS/Root, CVS/Repository, CVS/Tag, and CVS/Entries.static files to the |
215 |
* specified folder using the data contained in the specified FolderSyncInfo instance. |
312 |
* specified folder using the data contained in the specified FolderSyncInfo instance. |
216 |
*/ |
313 |
*/ |
Lines 265-270
Link Here
|
265 |
} |
362 |
} |
266 |
|
363 |
|
267 |
/** |
364 |
/** |
|
|
365 |
* Writes the CVS/Root, CVS/Repository, CVS/Tag, and CVS/Entries.static files to the |
366 |
* specified folder using the data contained in the specified FolderSyncInfo instance. |
367 |
*/ |
368 |
public static void writeFolderSync(IPath folder, FolderSyncInfo info) throws CVSException { |
369 |
try { |
370 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
371 |
System.out.println("Writing Root/Respository files for " + folder.toOSString()); //$NON-NLS-1$ |
372 |
} |
373 |
IPath cvsSubDir = createCVSSubdirectory(folder); |
374 |
|
375 |
// write CVS/Root |
376 |
writeLines(cvsSubDir.append(ROOT), new String[] {info.getRoot()}); |
377 |
|
378 |
// write CVS/Repository |
379 |
writeLines(cvsSubDir.append(REPOSITORY), new String[] {info.getRepository()}); |
380 |
|
381 |
// write CVS/Tag |
382 |
IPath tagFile = cvsSubDir.append(TAG); |
383 |
if (info.getTag() != null) { |
384 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
385 |
System.out.println("Writing Tag file for " + folder.toOSString()); //$NON-NLS-1$ |
386 |
} |
387 |
writeLines(tagFile, new String[] {info.getTag().toEntryLineFormat(false)}); |
388 |
} else { |
389 |
if(tagFile.toFile().exists()) { |
390 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
391 |
System.out.println("Deleting Tag file for " + folder.toOSString()); //$NON-NLS-1$ |
392 |
} |
393 |
tagFile.toFile().delete(); |
394 |
} |
395 |
} |
396 |
|
397 |
// write CVS/Entries.Static |
398 |
IPath staticFile = cvsSubDir.append(STATIC); |
399 |
if(info.getIsStatic()) { |
400 |
// the existance of the file is all that matters |
401 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
402 |
System.out.println("Writing Static file for " + folder.toOSString()); //$NON-NLS-1$ |
403 |
} |
404 |
writeLines(staticFile, new String[] {""}); //$NON-NLS-1$ |
405 |
} else { |
406 |
if(staticFile.toFile().exists()) { |
407 |
if (Policy.DEBUG_METAFILE_CHANGES) { |
408 |
System.out.println("Deleting Static file for " + folder.toOSString()); //$NON-NLS-1$ |
409 |
} |
410 |
staticFile.toFile().delete(); |
411 |
} |
412 |
} |
413 |
} catch(CoreException e) { |
414 |
throw CVSException.wrapException(e); |
415 |
} catch (IOException e) { |
416 |
throw CVSException.wrapException(e); |
417 |
} |
418 |
} |
419 |
|
420 |
/** |
268 |
* Returns all .cvsignore entries for the specified folder. |
421 |
* Returns all .cvsignore entries for the specified folder. |
269 |
*/ |
422 |
*/ |
270 |
public static String[] readCVSIgnoreEntries(IContainer folder) throws CVSException { |
423 |
public static String[] readCVSIgnoreEntries(IContainer folder) throws CVSException { |
Lines 328-342
Link Here
|
328 |
return null; |
481 |
return null; |
329 |
} |
482 |
} |
330 |
|
483 |
|
331 |
// process Notify file contents |
|
|
332 |
String[] entries = readLines(cvsSubDir.getFile(NOTIFY)); |
484 |
String[] entries = readLines(cvsSubDir.getFile(NOTIFY)); |
|
|
485 |
return readAllNotifyInfo(parent.getFullPath(), entries); |
486 |
} |
487 |
|
488 |
/** |
489 |
* Reads the CVS/Notify file from the specified folder and returns NotifyInfo instances |
490 |
* for the data stored therein. If the folder does not have a CVS subdirectory then <code>null</code> is returned. |
491 |
*/ |
492 |
public static NotifyInfo[] readAllNotifyInfo(IPath parent) throws CVSException { |
493 |
IPath cvsSubDir = getCVSSubdirectory(parent); |
494 |
|
495 |
if (!folderExists(cvsSubDir)){ |
496 |
return null; |
497 |
} |
498 |
|
499 |
String[] entries = readLines(cvsSubDir.append(NOTIFY)); |
500 |
return readAllNotifyInfo(parent, entries); |
501 |
} |
502 |
|
503 |
private static NotifyInfo[] readAllNotifyInfo(IPath path, String[] entries) throws CVSException { |
504 |
// process Notify file contents |
333 |
if (entries == null) return null; |
505 |
if (entries == null) return null; |
334 |
Map infos = new TreeMap(); |
506 |
Map infos = new TreeMap(); |
335 |
for (int i = 0; i < entries.length; i++) { |
507 |
for (int i = 0; i < entries.length; i++) { |
336 |
String line = entries[i]; |
508 |
String line = entries[i]; |
337 |
if(!"".equals(line)) { //$NON-NLS-1$ |
509 |
if(!"".equals(line)) { //$NON-NLS-1$ |
338 |
try { |
510 |
try { |
339 |
NotifyInfo info = new NotifyInfo(parent, line); |
511 |
NotifyInfo info = new NotifyInfo(path, line); |
340 |
infos.put(info.getName(), info); |
512 |
infos.put(info.getName(), info); |
341 |
} catch (CVSException e) { |
513 |
} catch (CVSException e) { |
342 |
// We couldn't parse the notify info |
514 |
// We couldn't parse the notify info |
Lines 383-388
Link Here
|
383 |
} |
555 |
} |
384 |
|
556 |
|
385 |
/** |
557 |
/** |
|
|
558 |
* Writes the CVS/Notify file to the specified folder using the data contained in the |
559 |
* specified NotifyInfo instances. A CVS subdirectory must already exist (an exception |
560 |
* is thrown if it doesn't). |
561 |
*/ |
562 |
public static void writeAllNotifyInfo(IPath parent, NotifyInfo[] infos) throws CVSException { |
563 |
// get the CVS directory |
564 |
IPath cvsSubDir = getCVSSubdirectory(parent); |
565 |
// write lines will throw an exception if the CVS directory does not exist |
566 |
|
567 |
if (infos.length == 0) { |
568 |
IPath notifyFile = cvsSubDir.append(NOTIFY); |
569 |
if(notifyFile.toFile().exists()) { |
570 |
notifyFile.toFile().delete(); |
571 |
} |
572 |
} else { |
573 |
// format file contents |
574 |
String[] entries = new String[infos.length]; |
575 |
for (int i = 0; i < infos.length; i++) { |
576 |
NotifyInfo info = infos[i]; |
577 |
entries[i] = info.getNotifyLine(); |
578 |
} |
579 |
|
580 |
// write Notify entries |
581 |
try { |
582 |
writeLines(cvsSubDir.append(NOTIFY), entries); |
583 |
} catch (IOException e) { |
584 |
throw CVSException.wrapException(e); |
585 |
} |
586 |
} |
587 |
} |
588 |
|
589 |
/** |
386 |
* Reads the CVS/Baserev file from the specified folder and returns |
590 |
* Reads the CVS/Baserev file from the specified folder and returns |
387 |
* BaserevInfo instances for the data stored therein. If the folder does not |
591 |
* BaserevInfo instances for the data stored therein. If the folder does not |
388 |
* have a CVS subdirectory then <code>null</code> is returned. |
592 |
* have a CVS subdirectory then <code>null</code> is returned. |
Lines 396-401
Link Here
|
396 |
|
600 |
|
397 |
// process Notify file contents |
601 |
// process Notify file contents |
398 |
String[] entries = readLines(cvsSubDir.getFile(BASEREV)); |
602 |
String[] entries = readLines(cvsSubDir.getFile(BASEREV)); |
|
|
603 |
return readAllBaserevInfo(entries); |
604 |
} |
605 |
|
606 |
/** |
607 |
* Reads the CVS/Baserev file from the specified folder and returns |
608 |
* BaserevInfo instances for the data stored therein. If the folder does not |
609 |
* have a CVS subdirectory then <code>null</code> is returned. |
610 |
*/ |
611 |
public static BaserevInfo[] readAllBaserevInfo(IPath parent) throws CVSException { |
612 |
IPath cvsSubDir = getCVSSubdirectory(parent); |
613 |
|
614 |
if (!folderExists(cvsSubDir)){ |
615 |
return null; |
616 |
} |
617 |
|
618 |
// process Notify file contents |
619 |
String[] entries = readLines(cvsSubDir.append(BASEREV)); |
620 |
return readAllBaserevInfo(entries); |
621 |
} |
622 |
|
623 |
private static BaserevInfo[] readAllBaserevInfo(String[] entries) |
624 |
throws CVSException { |
399 |
if (entries == null) return null; |
625 |
if (entries == null) return null; |
400 |
Map infos = new TreeMap(); |
626 |
Map infos = new TreeMap(); |
401 |
for (int i = 0; i < entries.length; i++) { |
627 |
for (int i = 0; i < entries.length; i++) { |
Lines 419-433
Link Here
|
419 |
IFolder cvsSubDir = getCVSSubdirectory(parent); |
645 |
IFolder cvsSubDir = getCVSSubdirectory(parent); |
420 |
// write lines will throw an exception if the CVS directory does not exist |
646 |
// write lines will throw an exception if the CVS directory does not exist |
421 |
|
647 |
|
|
|
648 |
String[] entries = formatBaserevInfo(infos); |
649 |
|
650 |
// write Notify entries |
651 |
writeLines(cvsSubDir.getFile(BASEREV), entries); |
652 |
} |
653 |
|
654 |
/** |
655 |
* Writes the CVS/Baserev file to the specified folder using the data |
656 |
* contained in the specified BaserevInfo instances. A CVS subdirectory must |
657 |
* already exist (an exception is thrown if it doesn't). |
658 |
*/ |
659 |
public static void writeAllBaserevInfo(IPath parent, BaserevInfo[] infos) throws CVSException { |
660 |
// get the CVS directory |
661 |
IPath cvsSubDir = getCVSSubdirectory(parent); |
662 |
// write lines will throw an exception if the CVS directory does not exist |
663 |
|
664 |
String[] entries = formatBaserevInfo(infos); |
665 |
|
666 |
// write Notify entries |
667 |
try { |
668 |
writeLines(cvsSubDir.append(BASEREV), entries); |
669 |
} catch (IOException e) { |
670 |
CVSException.wrapException(e); |
671 |
} |
672 |
} |
673 |
|
674 |
private static String[] formatBaserevInfo(BaserevInfo[] infos) { |
422 |
// format file contents |
675 |
// format file contents |
423 |
String[] entries = new String[infos.length]; |
676 |
String[] entries = new String[infos.length]; |
424 |
for (int i = 0; i < infos.length; i++) { |
677 |
for (int i = 0; i < infos.length; i++) { |
425 |
BaserevInfo info = infos[i]; |
678 |
BaserevInfo info = infos[i]; |
426 |
entries[i] = info.getEntryLine(); |
679 |
entries[i] = info.getEntryLine(); |
427 |
} |
680 |
} |
428 |
|
681 |
return entries; |
429 |
// write Notify entries |
|
|
430 |
writeLines(cvsSubDir.getFile(BASEREV), entries); |
431 |
} |
682 |
} |
432 |
|
683 |
|
433 |
/** |
684 |
/** |
Lines 438-443
Link Here
|
438 |
} |
689 |
} |
439 |
|
690 |
|
440 |
/** |
691 |
/** |
|
|
692 |
* Returns the CVS subdirectory for this folder. |
693 |
*/ |
694 |
private static IPath getCVSSubdirectory(IPath folder) { |
695 |
return folder.append(CVS_DIRNAME); |
696 |
} |
697 |
|
698 |
/** |
441 |
* Creates and makes team-private and returns a CVS subdirectory in this folder. |
699 |
* Creates and makes team-private and returns a CVS subdirectory in this folder. |
442 |
*/ |
700 |
*/ |
443 |
private static IFolder createCVSSubdirectory(IContainer folder) throws CVSException { |
701 |
private static IFolder createCVSSubdirectory(IContainer folder) throws CVSException { |
Lines 471-476
Link Here
|
471 |
} |
729 |
} |
472 |
} |
730 |
} |
473 |
|
731 |
|
|
|
732 |
/** |
733 |
* Creates and makes team-private and returns a CVS subdirectory in this folder. |
734 |
*/ |
735 |
private static IPath createCVSSubdirectory(IPath folder) throws CVSException { |
736 |
final IPath cvsSubDir = getCVSSubdirectory(folder); |
737 |
if (! cvsSubDir.toFile().exists()) |
738 |
cvsSubDir.toFile().mkdir(); |
739 |
return cvsSubDir; |
740 |
} |
741 |
|
474 |
protected static boolean existsInFileSystem(IFolder cvsSubDir) { |
742 |
protected static boolean existsInFileSystem(IFolder cvsSubDir) { |
475 |
URI uri = cvsSubDir.getLocationURI(); |
743 |
URI uri = cvsSubDir.getLocationURI(); |
476 |
if (uri != null) { |
744 |
if (uri != null) { |
Lines 493-498
Link Here
|
493 |
private static String readFirstLine(IFile file) throws CVSException { |
761 |
private static String readFirstLine(IFile file) throws CVSException { |
494 |
try { |
762 |
try { |
495 |
InputStream in = getInputStream(file); |
763 |
InputStream in = getInputStream(file); |
|
|
764 |
return readFirstLine(in); |
765 |
} catch (IOException e) { |
766 |
throw CVSException.wrapException(e); |
767 |
} catch (CoreException e) { |
768 |
// If the IFile doesn't exist or the underlying File doesn't exist, |
769 |
// just return null to indicate the absence of the file |
770 |
if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND |
771 |
|| e.getStatus().getCode() == IResourceStatus.FAILED_READ_LOCAL) |
772 |
return null; |
773 |
throw CVSException.wrapException(e); |
774 |
} |
775 |
} |
776 |
|
777 |
/* |
778 |
* Reads the first line of the specified file. |
779 |
* Returns null if the file does not exist, or the empty string if it is blank. |
780 |
*/ |
781 |
private static String readFirstLine(IPath file) throws CVSException { |
782 |
try { |
783 |
if (!file.toFile().exists()) |
784 |
return null; |
785 |
InputStream in = new FileInputStream(file.toFile()); |
786 |
return readFirstLine(in); |
787 |
} catch (IOException e) { |
788 |
throw CVSException.wrapException(e); |
789 |
} |
790 |
} |
791 |
|
792 |
private static String readFirstLine(InputStream in) throws IOException { |
496 |
if (in != null) { |
793 |
if (in != null) { |
497 |
BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512); |
794 |
BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512); |
498 |
try { |
795 |
try { |
Lines 504-519
Link Here
|
504 |
} |
801 |
} |
505 |
} |
802 |
} |
506 |
return null; |
803 |
return null; |
507 |
} catch (IOException e) { |
|
|
508 |
throw CVSException.wrapException(e); |
509 |
} catch (CoreException e) { |
510 |
// If the IFile doesn't exist or the underlying File doesn't exist, |
511 |
// just return null to indicate the absence of the file |
512 |
if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND |
513 |
|| e.getStatus().getCode() == IResourceStatus.FAILED_READ_LOCAL) |
514 |
return null; |
515 |
throw CVSException.wrapException(e); |
516 |
} |
517 |
} |
804 |
} |
518 |
|
805 |
|
519 |
private static InputStream getInputStream(IFile file) throws CoreException, FileNotFoundException { |
806 |
private static InputStream getInputStream(IFile file) throws CoreException, FileNotFoundException { |
Lines 547-552
Link Here
|
547 |
private static String[] readLines(IFile file) throws CVSException { |
834 |
private static String[] readLines(IFile file) throws CVSException { |
548 |
try { |
835 |
try { |
549 |
InputStream in = getInputStream(file); |
836 |
InputStream in = getInputStream(file); |
|
|
837 |
return readLines(in); |
838 |
} catch (IOException e) { |
839 |
throw CVSException.wrapException(e); |
840 |
} catch (CoreException e) { |
841 |
// If the IFile doesn't exist or the underlying File doesn't exist, |
842 |
// just return null to indicate the absence of the file |
843 |
if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND |
844 |
|| e.getStatus().getCode() == IResourceStatus.FAILED_READ_LOCAL) |
845 |
return null; |
846 |
throw CVSException.wrapException(e); |
847 |
} |
848 |
} |
849 |
|
850 |
private static String[] readLines(InputStream in) throws IOException { |
550 |
if (in != null) { |
851 |
if (in != null) { |
551 |
BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512); |
852 |
BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512); |
552 |
List fileContentStore = new ArrayList(); |
853 |
List fileContentStore = new ArrayList(); |
Lines 561-574
Link Here
|
561 |
} |
862 |
} |
562 |
} |
863 |
} |
563 |
return null; |
864 |
return null; |
564 |
} catch (IOException e) { |
865 |
} |
565 |
throw CVSException.wrapException(e); |
866 |
|
566 |
} catch (CoreException e) { |
867 |
/* |
567 |
// If the IFile doesn't exist or the underlying File doesn't exist, |
868 |
* Reads all lines of the specified file. |
568 |
// just return null to indicate the absence of the file |
869 |
* Returns null if the file does not exist. |
569 |
if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND |
870 |
*/ |
570 |
|| e.getStatus().getCode() == IResourceStatus.FAILED_READ_LOCAL) |
871 |
private static String[] readLines(IPath file) throws CVSException { |
|
|
872 |
try { |
873 |
if (!file.toFile().exists()) |
571 |
return null; |
874 |
return null; |
|
|
875 |
InputStream in = new FileInputStream(file.toFile()); |
876 |
return readLines(in); |
877 |
} catch (IOException e) { |
572 |
throw CVSException.wrapException(e); |
878 |
throw CVSException.wrapException(e); |
573 |
} |
879 |
} |
574 |
} |
880 |
} |
Lines 604-609
Link Here
|
604 |
} |
910 |
} |
605 |
} |
911 |
} |
606 |
|
912 |
|
|
|
913 |
/* |
914 |
* Writes all lines to the specified file, using linefeed terminators for |
915 |
* compatibility with other CVS clients. |
916 |
*/ |
917 |
private static void writeLines(IPath file, final String[] contents) throws IOException, CVSException { |
918 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
919 |
writeLinesToStreamAndClose(os, contents); |
920 |
File javaFile = file.toFile(); |
921 |
RandomAccessFile raFile = new RandomAccessFile(javaFile, "rw"); //$NON-NLS-1$ |
922 |
raFile.write(os.toByteArray()); |
923 |
raFile.setLength(os.toByteArray().length); |
924 |
raFile.close(); |
925 |
} |
926 |
|
607 |
private static void writeLinesToStreamAndClose(OutputStream os, String[] contents) throws CVSException { |
927 |
private static void writeLinesToStreamAndClose(OutputStream os, String[] contents) throws CVSException { |
608 |
byte[] lineEnd = getLineDelimiter(); |
928 |
byte[] lineEnd = getLineDelimiter(); |
609 |
try { |
929 |
try { |
Lines 650-655
Link Here
|
650 |
} |
970 |
} |
651 |
} |
971 |
} |
652 |
/** |
972 |
/** |
|
|
973 |
* Method writeFileToBaseDirectory. |
974 |
* |
975 |
* @param file |
976 |
* @param info |
977 |
*/ |
978 |
public static void writeFileToBaseDirectory(IPath file, IProgressMonitor monitor) throws CVSException { |
979 |
monitor = Policy.monitorFor(monitor); |
980 |
monitor.beginTask(null, 100); |
981 |
try { |
982 |
IPath baseFolder = getBaseDirectory(file); |
983 |
if (!baseFolder.toFile().exists()) { |
984 |
baseFolder.toFile().createNewFile(); |
985 |
} |
986 |
IPath target = baseFolder.append(file.lastSegment()); |
987 |
if (target.toFile().exists()) { |
988 |
// XXX Should ensure that we haven't already copied it |
989 |
// XXX write the revision to the CVS/Baserev file |
990 |
setReadOnly(target, false); |
991 |
target.toFile().delete(); |
992 |
} |
993 |
InputStream in = new FileInputStream(file.toFile()); |
994 |
OutputStream out = new FileOutputStream(target.toFile()); |
995 |
|
996 |
// Transfer bytes from in to out |
997 |
byte[] buf = new byte[1024]; |
998 |
int len; |
999 |
while ((len = in.read(buf)) > 0) { |
1000 |
out.write(buf, 0, len); |
1001 |
} |
1002 |
in.close(); |
1003 |
out.close(); |
1004 |
target.toFile().setLastModified(file.toFile().lastModified()); |
1005 |
} catch (IOException e) { |
1006 |
throw CVSException.wrapException(e); |
1007 |
} finally { |
1008 |
monitor.done(); |
1009 |
} |
1010 |
} |
1011 |
/** |
653 |
* Method restoreFileFromBaseDirectory. |
1012 |
* Method restoreFileFromBaseDirectory. |
654 |
* @param file |
1013 |
* @param file |
655 |
* @param info |
1014 |
* @param info |
Lines 678-683
Link Here
|
678 |
monitor.done(); |
1037 |
monitor.done(); |
679 |
} |
1038 |
} |
680 |
} |
1039 |
} |
|
|
1040 |
/** |
1041 |
* Method restoreFileFromBaseDirectory. |
1042 |
* @param file |
1043 |
* @param info |
1044 |
* @param monitor |
1045 |
*/ |
1046 |
public static void restoreFileFromBaseDirectory(IPath file, IProgressMonitor monitor) throws CVSException { |
1047 |
monitor = Policy.monitorFor(monitor); |
1048 |
monitor.beginTask(null, 100); |
1049 |
try { |
1050 |
IPath baseFolder = getBaseDirectory(file); |
1051 |
IPath source = baseFolder.append(file.lastSegment()); |
1052 |
if (!source.toFile().exists()) { |
1053 |
IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.ERROR, NLS.bind(CVSMessages.SyncFileWriter_baseNotAvailable, new String[] { file.toOSString() }), file); |
1054 |
throw new CVSException(status); |
1055 |
} |
1056 |
if (file.toFile().exists()) { |
1057 |
file.toFile().delete(); |
1058 |
} |
1059 |
// Make the source writable to avoid problems on some file systems (bug 109308) |
1060 |
setReadOnly(source, false); |
1061 |
// Copy the file so the timestamp is maintained |
1062 |
source.toFile().renameTo(file.toFile()); |
1063 |
} catch (CoreException e) { |
1064 |
throw CVSException.wrapException(e); |
1065 |
} finally { |
1066 |
monitor.done(); |
1067 |
} |
1068 |
} |
681 |
|
1069 |
|
682 |
private static void setReadOnly(IFile source, boolean readOnly) { |
1070 |
private static void setReadOnly(IFile source, boolean readOnly) { |
683 |
ResourceAttributes attrs = source.getResourceAttributes(); |
1071 |
ResourceAttributes attrs = source.getResourceAttributes(); |
Lines 692-697
Link Here
|
692 |
} |
1080 |
} |
693 |
} |
1081 |
} |
694 |
|
1082 |
|
|
|
1083 |
private static void setReadOnly(IPath source, boolean readOnly) { |
1084 |
try { |
1085 |
IFileStore fileStore = EFS.getStore(source.toFile().toURI()); |
1086 |
if (fileStore != null) { |
1087 |
IFileInfo fileInfo = fileStore.fetchInfo(); |
1088 |
if (fileInfo != null) |
1089 |
fileInfo.setAttribute(EFS.ATTRIBUTE_READ_ONLY, readOnly); |
1090 |
} |
1091 |
} catch (CoreException e) { |
1092 |
CVSException.wrapException(e); |
1093 |
} |
1094 |
} |
1095 |
|
695 |
/** |
1096 |
/** |
696 |
* Method deleteFileFromBaseDirectory. |
1097 |
* Method deleteFileFromBaseDirectory. |
697 |
* @param file |
1098 |
* @param file |
Lines 714-725
Link Here
|
714 |
} |
1115 |
} |
715 |
} |
1116 |
} |
716 |
|
1117 |
|
|
|
1118 |
/** |
1119 |
* Method deleteFileFromBaseDirectory. |
1120 |
* @param file |
1121 |
* @param monitor |
1122 |
*/ |
1123 |
public static void deleteFileFromBaseDirectory(IPath file, IProgressMonitor monitor) throws CVSException { |
1124 |
monitor = Policy.monitorFor(monitor); |
1125 |
monitor.beginTask(null, 100); |
1126 |
try { |
1127 |
IPath baseFolder = getBaseDirectory(file); |
1128 |
IPath source = baseFolder.append(file.lastSegment()); |
1129 |
if (source.toFile().exists()) { |
1130 |
setReadOnly(source, false); |
1131 |
source.toFile().delete(); |
1132 |
} |
1133 |
} finally { |
1134 |
monitor.done(); |
1135 |
} |
1136 |
} |
1137 |
|
717 |
private static IFolder getBaseDirectory(IFile file) { |
1138 |
private static IFolder getBaseDirectory(IFile file) { |
718 |
IContainer cvsFolder = getCVSSubdirectory(file.getParent()); |
1139 |
IContainer cvsFolder = getCVSSubdirectory(file.getParent()); |
719 |
IFolder baseFolder = cvsFolder.getFolder(new Path(BASE_DIRNAME)); |
1140 |
IFolder baseFolder = cvsFolder.getFolder(new Path(BASE_DIRNAME)); |
720 |
return baseFolder; |
1141 |
return baseFolder; |
721 |
} |
1142 |
} |
722 |
|
1143 |
|
|
|
1144 |
private static IPath getBaseDirectory(IPath file) { |
1145 |
IPath cvsFolder = getCVSSubdirectory(file.removeLastSegments(1)); |
1146 |
IPath baseFolder = cvsFolder.append(new Path(BASE_DIRNAME)); |
1147 |
return baseFolder; |
1148 |
} |
1149 |
|
723 |
/** |
1150 |
/** |
724 |
* Return a handle to the CVS/Template file for the given folder |
1151 |
* Return a handle to the CVS/Template file for the given folder |
725 |
* @param folder |
1152 |
* @param folder |
Lines 742-747
Link Here
|
742 |
return baseFile.exists(); |
1169 |
return baseFile.exists(); |
743 |
} |
1170 |
} |
744 |
|
1171 |
|
|
|
1172 |
/** |
1173 |
* Method isEdited. |
1174 |
* @param resource |
1175 |
* @return boolean |
1176 |
*/ |
1177 |
public static boolean isEdited(IPath file) { |
1178 |
IPath baseFolder = getBaseDirectory(file); |
1179 |
IPath baseFile = baseFolder.append(file.lastSegment()); |
1180 |
return baseFile.toFile().exists(); |
1181 |
} |
1182 |
|
745 |
private static byte[] getLineDelimiter() { |
1183 |
private static byte[] getLineDelimiter() { |
746 |
if (CVSProviderPlugin.getPlugin().isUsePlatformLineend()) { |
1184 |
if (CVSProviderPlugin.getPlugin().isUsePlatformLineend()) { |
747 |
String property = System.getProperty("line.separator"); //$NON-NLS-1$ |
1185 |
String property = System.getProperty("line.separator"); //$NON-NLS-1$ |