001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.command.fs;
034:
035: import org.libresource.so6.core.WsConnection;
036: import org.libresource.so6.core.engine.DBType;
037: import org.libresource.so6.core.engine.util.FileUtils;
038:
039: import java.io.File;
040: import java.io.Serializable;
041:
042: public class UpdateBinaryFile extends FsCommand implements Serializable {
043: private static final long serialVersionUID = 3;
044:
045: public UpdateBinaryFile(long ticket, String path, String wsName,
046: long time, boolean conflict, String attachement) {
047: super (ticket, path, wsName, time, conflict, attachement);
048: }
049:
050: public UpdateBinaryFile(String path, WsConnection ws) {
051: super (path, ws);
052:
053: String tmppath;
054:
055: try {
056: tmppath = File.createTempFile("grouss", null).getPath();
057:
058: File f = new File(tmppath);
059: f.deleteOnExit();
060: FileUtils.copy(ws.getPath() + File.separator + path,
061: tmppath);
062: } catch (Exception e) {
063: throw new RuntimeException(e);
064: }
065:
066: this .setAttachement(tmppath);
067: }
068:
069: public UpdateBinaryFile(String path, WsConnection ws,
070: File tmpDestDir) {
071: super (path, ws);
072:
073: String tmppath;
074:
075: try {
076: tmppath = File.createTempFile("attach", null, tmpDestDir)
077: .getPath();
078:
079: File f = new File(tmppath);
080: FileUtils.copy(ws.getPath() + File.separator + path,
081: tmppath);
082: } catch (Exception e) {
083: throw new RuntimeException(e);
084: }
085:
086: this .setAttachement(tmppath);
087: }
088:
089: public boolean equals(Object o) {
090: if (o instanceof UpdateBinaryFile) {
091: UpdateBinaryFile ubf = (UpdateBinaryFile) o;
092:
093: if (path.equals(ubf.path)) {
094: if (getTicket() == ubf.getTicket()) {
095: return true;
096: }
097:
098: if ((getTicket() == -1) || (ubf.getTicket() == -1)) {
099: return FileUtils.compareBinFile(new File(this
100: .getAttachement()), new File(ubf
101: .getAttachement()));
102: }
103:
104: return false;
105: } else {
106: return false;
107: }
108: } else {
109: return false;
110: }
111: }
112:
113: public String toString() {
114: return "UpdateBinaryFile(" + path + ")";
115: }
116:
117: public void execute(String dir, DBType dbt) throws Exception {
118: FileUtils.copy(this.getAttachement(), dir + File.separator
119: + path);
120: }
121: }
|