Commit | Line | Data |
---|---|---|
f17bb886 MAL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Marc-Andre Laperle - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace; | |
14 | ||
15 | import java.io.File; | |
16 | import java.io.IOException; | |
17 | import java.net.URI; | |
18 | ||
6120dc63 | 19 | import org.apache.commons.compress.archivers.tar.TarArchiveEntry; |
f17bb886 MAL |
20 | import org.eclipse.core.runtime.IPath; |
21 | import org.eclipse.core.runtime.Path; | |
22 | import org.eclipse.core.runtime.URIUtil; | |
f17bb886 MAL |
23 | |
24 | /** | |
25 | * The "Tar" implementation of an IFileSystemObject, entries can also be Gzipped | |
26 | * and are uncompressed transparently. | |
27 | */ | |
f17bb886 MAL |
28 | class TarFileSystemObject implements IFileSystemObject { |
29 | ||
6120dc63 | 30 | private TarArchiveEntry fFileSystemObject; |
f17bb886 MAL |
31 | private String fArchivePath; |
32 | ||
6120dc63 | 33 | TarFileSystemObject(TarArchiveEntry fileSystemObject, String archivePath) { |
f17bb886 MAL |
34 | fFileSystemObject = fileSystemObject; |
35 | fArchivePath = archivePath; | |
36 | } | |
37 | ||
38 | @Override | |
39 | public String getName() { | |
40 | return new Path(fFileSystemObject.getName()).lastSegment(); | |
41 | } | |
42 | ||
43 | @Override | |
44 | public String getAbsolutePath() { | |
45 | throw new UnsupportedOperationException(); | |
46 | } | |
47 | ||
48 | @Override | |
49 | public boolean exists() { | |
50 | return true; | |
51 | } | |
52 | ||
53 | @Override | |
54 | public String getSourceLocation() { | |
55 | File file = new File(fArchivePath); | |
56 | try { | |
57 | file = file.getCanonicalFile(); | |
58 | } catch (IOException e) { | |
59 | // Will still work but might have extra ../ in the path | |
60 | } | |
61 | URI uri = file.toURI(); | |
62 | IPath entryPath = new Path(fFileSystemObject.getName()); | |
63 | ||
64 | URI jarURI = entryPath.isRoot() ? URIUtil.toJarURI(uri, Path.EMPTY) : URIUtil.toJarURI(uri, entryPath); | |
65 | return URIUtil.toUnencodedString(jarURI); | |
66 | } | |
67 | ||
68 | @Override | |
69 | public Object getRawFileSystemObject() { | |
70 | return fFileSystemObject; | |
71 | } | |
537cd2b8 MAL |
72 | |
73 | @Override | |
74 | public boolean isDirectory() { | |
6120dc63 | 75 | return fFileSystemObject.isDirectory(); |
537cd2b8 | 76 | } |
f17bb886 | 77 | } |