Builds a data clip for the document(s) to be added. @return success flag
()
| 71 | * @return success flag |
| 72 | */ |
| 73 | boolean build() { |
| 74 | String path = MetaData.normPath(args[0]); |
| 75 | if(path == null) return error(PATH_INVALID_X, args[0]); |
| 76 | |
| 77 | // retrieve input |
| 78 | final IO source; |
| 79 | try { |
| 80 | source = sourceToIO(path); |
| 81 | } catch(final IOException ex) { |
| 82 | return error(Util.message(ex)); |
| 83 | } |
| 84 | |
| 85 | // check if resource exists |
| 86 | if(source == null) return error(RES_NOT_FOUND); |
| 87 | if(!source.exists()) return in != null ? error(RES_NOT_FOUND) : |
| 88 | error(RES_NOT_FOUND_X, context.user().has(Perm.CREATE) ? source : args[1]); |
| 89 | |
| 90 | if(!Strings.endsWith(path, '/') && (source.isDir() || source.isArchive())) path += '/'; |
| 91 | |
| 92 | String target = ""; |
| 93 | final int s = path.lastIndexOf('/'); |
| 94 | if(s != -1) { |
| 95 | target = path.substring(0, s); |
| 96 | path = path.substring(s + 1); |
| 97 | } |
| 98 | |
| 99 | // get name from io reference |
| 100 | if(path.isEmpty()) path = source.name(); |
| 101 | else source.name(path); |
| 102 | |
| 103 | // ensure that the final name is not empty |
| 104 | if(path.isEmpty()) return error(NAME_INVALID_X, path); |
| 105 | |
| 106 | try { |
| 107 | final Data data = context.data(); |
| 108 | final String name = data.meta.name; |
| 109 | final Parser parser = new DirParser(source, options).target(target); |
| 110 | |
| 111 | // create random database name for disk-based creation |
| 112 | if(cache(parser)) { |
| 113 | final String tmpName = soptions.createTempDb(name); |
| 114 | builder = new DiskBuilder(tmpName, parser, soptions, options); |
| 115 | } else { |
| 116 | builder = new MemBuilder(path, parser); |
| 117 | } |
| 118 | |
| 119 | if(!data.inMemory()) builder.binariesDir(soptions.dbPath(name)); |
| 120 | tmpData = builder.build(); |
| 121 | return true; |
| 122 | } catch(final IOException ex) { |
| 123 | return error(Util.message(ex)); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Finalizes an add operation. |
no test coverage detected