annotate src/org/tmatesoft/hg/internal/FileUtils.java @ 697:24f4efedc9d5

Respect the fact ssh and http protocols use different compression approach to sent changegroup data
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 06 Aug 2013 13:34:34 +0200
parents 12a4f60ea972
children b4242b7e7dfe
rev   line source
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Debug;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.Closeable;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.File;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.FileInputStream;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.FileOutputStream;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.io.IOException;
697
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
26 import java.io.InputStream;
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.nio.channels.FileChannel;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.core.HgIOException;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.util.LogFacility;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.util.LogFacility.Severity;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 /**
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 *
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author Artem Tikhomirov
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author TMate Software Ltd.
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 */
619
868b2ffdcd5c Close FIS, not FileChannel, to clear both references to FileDescriptor right away
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
38 public final class FileUtils {
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private final LogFacility log;
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
41 private final Class<?> troublemaker;
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 public static void copyFile(File from, File to) throws HgIOException {
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
44 new FileUtils(new StreamLogFacility(Debug, true, System.err), FileUtils.class).copy(from, to);
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 }
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
47 public FileUtils(LogFacility logFacility, Object troubleSource) {
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 log = logFacility;
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
49 if (troubleSource == null) {
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
50 troublemaker = null;
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
51 } else {
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
52 troublemaker = troubleSource instanceof Class ? (Class<?>) troubleSource : troubleSource.getClass();
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
53 }
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 }
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 public void copy(File from, File to) throws HgIOException {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 FileInputStream fis = null;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 FileOutputStream fos = null;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 try {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 fis = new FileInputStream(from);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 fos = new FileOutputStream(to);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 FileChannel input = fis.getChannel();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 FileChannel output = fos.getChannel();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 long count = input.size();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 long pos = 0;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 int zeroCopied = 0; // flag to prevent hang-up
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 do {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 long c = input.transferTo(pos, count, output);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 pos += c;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 count -= c;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 if (c == 0) {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 if (++zeroCopied == 3) {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 String m = String.format("Can't copy %s to %s, transferTo copies 0 bytes. Position: %d, bytes left:%d", from.getName(), to.getName(), pos, count);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 throw new IOException(m);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 }
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 } else {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 // reset
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 zeroCopied = 0;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 }
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 } while (count > 0);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 fos.close();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 fos = null;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 fis.close();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 fis = null;
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 } catch (IOException ex) {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 // not in finally because I don't want to loose exception from fos.close()
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
87 closeQuietly(fis, from);
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
88 closeQuietly(fos, to);
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 String m = String.format("Failed to copy %s to %s", from.getName(), to.getName());
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 throw new HgIOException(m, ex, from);
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 }
624
507602cb4fb3 FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 619
diff changeset
92 /* Copy of cpython's 00changelog.d, 20Mb+
507602cb4fb3 FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 619
diff changeset
93 * Linux&Windows: 300-400 ms,
507602cb4fb3 FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 619
diff changeset
94 * Windows uncached run: 1.6 seconds
507602cb4fb3 FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 619
diff changeset
95 */
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 }
697
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
97
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
98 public void write(InputStream is, File file) throws IOException {
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
99 FileOutputStream fos = new FileOutputStream(file);
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
100 int r;
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
101 byte[] buf = new byte[8*1024];
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
102 while ((r = is.read(buf)) != -1) {
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
103 fos.write(buf, 0, r);
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
104 }
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
105 fos.flush();
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
106 fos.close();
24f4efedc9d5 Respect the fact ssh and http protocols use different compression approach to sent changegroup data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
107 }
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
108
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 public void closeQuietly(Closeable stream) {
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
110 closeQuietly(stream, null);
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
111 }
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
112
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
113 public void closeQuietly(Closeable stream, File f) {
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 if (stream != null) {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 try {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 stream.close();
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 } catch (IOException ex) {
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 // ignore
636
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
119 final String msg;
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
120 if (f == null) {
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
121 msg = "Exception while closing stream quietly";
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
122 } else {
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
123 msg = String.format("Failed to close %s", f);
ffce73efa2c2 HgCommitCommand: save last commit message
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 624
diff changeset
124 }
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 636
diff changeset
125 log.dump(troublemaker == null ? getClass() : troublemaker, Severity.Warn, ex, msg);
617
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 }
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 }
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 }
65c01508f002 Rollback support for commands that modify repository. Strategy to keep complete copy of a file being changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 }