~unity-api-team/storage-framework/devel

« back to all changes in this revision

Viewing changes to src/local-provider/LocalUploadJob.cpp

  • Committer: Tarmac
  • Author(s): Michi Henning
  • Date: 2017-04-06 08:09:37 UTC
  • mfrom: (118.2.14 add-doc)
  • Revision ID: tarmac-20170406080937-97zduhlyym3yzftj
Added tutorial and provider reference documentation.

Approved by unity-api-1-bot, Michi Henning, James Henstridge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
        auto st = status(item_id);
84
84
        if (!is_regular_file(st))
85
85
        {
86
 
            throw InvalidArgumentException(method_ + ": \"" + item_id + "\" is not a file");
 
86
            throw LogicException(method_ + ": \"" + item_id + "\" is not a file");
87
87
        }
88
88
    }
89
89
    // LCOV_EXCL_START
99
99
        int64_t mtime = get_mtime_nsecs(method_, item_id);
100
100
        if (to_string(mtime) != old_etag)
101
101
        {
102
 
            throw ConflictException(method_ + ": etag mismatch");
 
102
            throw ConflictException(method_ + ": ETag mismatch");
103
103
        }
104
104
    }
105
105
    old_etag_ = old_etag;
184
184
 
185
185
    try
186
186
    {
187
 
        // We check again for an etag mismatch or overwrite, in case the file was updated after the upload started.
 
187
        // We check again for an ETag mismatch or overwrite, in case the file was updated after the upload started.
188
188
        if (!parent_id_.empty())
189
189
        {
190
190
            // create_file()
191
191
            if (!allow_overwrite_ && boost::filesystem::exists(item_id_))
192
192
            {
193
193
                string msg = method_ + ": \"" + item_id_ + "\" exists already";
194
 
                boost::filesystem::path(item_id_).filename().native();
195
194
                BOOST_THROW_EXCEPTION(
196
195
                    ExistsException(msg, item_id_, boost::filesystem::path(item_id_).filename().native()));
197
196
            }
199
198
        else if (!old_etag_.empty())
200
199
        {
201
200
            // update()
 
201
            using namespace boost::filesystem;
 
202
            if (exists(item_id_) && !is_regular_file(item_id_))
 
203
            {
 
204
                // Yes, ExistsException, not LogicException. A folder is in the way
 
205
                // and was created after the update started, meaning that the client correctly
 
206
                // started the operation with an existing file, but then the file was removed
 
207
                // and replaced with a folder with the same name.
 
208
                string msg = method_ + ": \"" + item_id_ + "\" exists already";
 
209
                BOOST_THROW_EXCEPTION(
 
210
                    ExistsException(msg, item_id_, boost::filesystem::path(item_id_).filename().native()));
 
211
            }
202
212
            int64_t mtime = get_mtime_nsecs(method_, item_id_);
203
213
            if (to_string(mtime) != old_etag_)
204
214
            {
205
 
                BOOST_THROW_EXCEPTION(ConflictException(method_ + ": etag mismatch"));
 
215
                // File was touched after the upload started.
 
216
                BOOST_THROW_EXCEPTION(ConflictException(method_ + ": ETag mismatch"));
206
217
            }
207
218
        }
208
219