| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | protected boolean run() { |
| 48 | final boolean create = context.user().has(Perm.CREATE); |
| 49 | String path = MetaData.normPath(args[0]); |
| 50 | if(path == null) return error(PATH_INVALID_X, args[0]); |
| 51 | |
| 52 | if(in == null) { |
| 53 | final IO io = IO.get(args[1]); |
| 54 | if(!io.exists() || io.isDir()) return error(RES_NOT_FOUND_X, create ? io : args[1]); |
| 55 | in = io.inputSource(); |
| 56 | // set/add name of document |
| 57 | if((path.isEmpty() || Strings.endsWith(path, '/')) && !(io instanceof IOContent)) { |
| 58 | path += io.name(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // ensure that the name is not empty and contains no trailing dots |
| 63 | final Data data = context.data(); |
| 64 | if(data.inMemory()) return error(NO_MAINMEM); |
| 65 | if(path.isEmpty()) return error(PATH_INVALID_X, create ? path : args[0]); |
| 66 | |
| 67 | final IOFile bin = data.meta.file(path, ResourceType.BINARY); |
| 68 | final String pth = path; |
| 69 | return update(data, () -> put(data, bin, pth)); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Puts a binary resource in the specified database. |