|
13 | 13 | import com.sun.jersey.client.apache4.ApacheHttpClient4;
|
14 | 14 | import com.sun.jersey.client.apache4.ApacheHttpClient4Handler;
|
15 | 15 | import com.sun.jersey.core.util.MultivaluedMapImpl;
|
| 16 | + |
16 | 17 | import org.apache.commons.codec.binary.Base64;
|
17 | 18 | import org.apache.commons.io.FileUtils;
|
18 | 19 | import org.apache.commons.io.IOUtils;
|
|
33 | 34 |
|
34 | 35 | import javax.ws.rs.core.MediaType;
|
35 | 36 | import javax.ws.rs.core.MultivaluedMap;
|
| 37 | + |
36 | 38 | import java.io.File;
|
37 | 39 | import java.io.IOException;
|
38 | 40 | import java.io.InputStream;
|
39 | 41 | import java.io.StringWriter;
|
| 42 | +import java.net.URI; |
| 43 | +import java.net.URISyntaxException; |
40 | 44 | import java.util.ArrayList;
|
41 | 45 | import java.util.List;
|
42 | 46 | import java.util.UUID;
|
@@ -788,6 +792,16 @@ public ClientResponse build(File dockerFolder) throws DockerException {
|
788 | 792 | public ClientResponse build(File dockerFolder, String tag) throws DockerException {
|
789 | 793 | return this.build(dockerFolder, tag, false);
|
790 | 794 | }
|
| 795 | + |
| 796 | + private static boolean isFileResource(String resource) { |
| 797 | + URI uri; |
| 798 | + try { |
| 799 | + uri = new URI(resource); |
| 800 | + } catch (URISyntaxException e) { |
| 801 | + throw new RuntimeException(e); |
| 802 | + } |
| 803 | + return uri.getScheme() == null || "file".equals(uri.getScheme()); |
| 804 | + } |
791 | 805 |
|
792 | 806 | public ClientResponse build(File dockerFolder, String tag, boolean noCache) throws DockerException {
|
793 | 807 | Preconditions.checkNotNull(dockerFolder, "Folder is null");
|
@@ -826,19 +840,25 @@ public ClientResponse build(File dockerFolder, String tag, boolean noCache) thro
|
826 | 840 | throw new DockerException(String.format("Wrong format on line [%s]", cmd));
|
827 | 841 | }
|
828 | 842 |
|
829 |
| - File src = new File(addArgs[1]); |
830 |
| - if (!src.isAbsolute()) { |
831 |
| - src = new File(dockerFolder, addArgs[1]).getCanonicalFile(); |
832 |
| - } |
833 |
| - |
834 |
| - if (!src.exists()) { |
835 |
| - throw new DockerException(String.format("Source file %s doesn't exist", src)); |
836 |
| - } |
837 |
| - if (src.isDirectory()) { |
838 |
| - filesToAdd.addAll(FileUtils.listFiles(src, null, true)); |
839 |
| - } else { |
840 |
| - filesToAdd.add(src); |
841 |
| - } |
| 843 | + String resource = addArgs[1]; |
| 844 | + |
| 845 | + if(isFileResource(resource)) { |
| 846 | + File src = new File(resource); |
| 847 | + if (!src.isAbsolute()) { |
| 848 | + src = new File(dockerFolder, resource).getCanonicalFile(); |
| 849 | + } else { |
| 850 | + throw new DockerException(String.format("Source file %s must be relative to %s", src, dockerFolder)); |
| 851 | + } |
| 852 | + |
| 853 | + if (!src.exists()) { |
| 854 | + throw new DockerException(String.format("Source file %s doesn't exist", src)); |
| 855 | + } |
| 856 | + if (src.isDirectory()) { |
| 857 | + filesToAdd.addAll(FileUtils.listFiles(src, null, true)); |
| 858 | + } else { |
| 859 | + filesToAdd.add(src); |
| 860 | + } |
| 861 | + } |
842 | 862 | }
|
843 | 863 | }
|
844 | 864 |
|
|
0 commit comments