Revision fed93cda

View differences:

include/MarketPlaceAppPool.h
145 145
    {
146 146
        return new MarketPlaceApp(-1,-1,"","", 0, 0);
147 147
    };
148

  
149
    /**
150
     * Erease map element
151
     */
152
    void drop_map_check(const std::string& name){
153
        if (map_check.find( name ) != map_check.end()){
154
            map<std::string,int>::iterator it;
155
            it=map_check.find(name);
156
            map_check.erase (it);
157
        }
158
    }
159

  
160
    /**
161
     * Check an element into map
162
     */
163
    bool test_map_check(const std::string& name){
164
        map_check[name]++;
165
        if (map_check[name] > 0){
166
            return true;
167
        }
168
        return false;
169
    }
170
private:
171
    map<std::string, int> map_check;
172

  
173
    
174
    void insert_map_check(const std::string& name){
175
        map_check.insert(make_pair(name, -1));
176
    }
177
    void reset_map_check(const std::string& name){
178
        if (name != "") {
179
            if (map_check.find( name ) != map_check.end()){
180
                map_check[name] = -1;
181
            }
182
            else{
183
                insert_map_check(name);
184
            }
185
        }
186
    }
148 187
};
149 188

  
150 189
#endif /*MARKETPLACE_POOL_H_*/
src/market/MarketPlaceAppPool.cc
128 128

  
129 129
    *oid = PoolSQL::allocate(mp, error_str);
130 130

  
131
    // ------------------------------------------------------------------------
132
    // Insert id into map_check
133
    // --------------------------------------------------------------------------
134
    insert_map_check(name);
135

  
131 136
    return *oid;
132 137

  
133 138
error_duplicated:
......
183 188
        return 0;
184 189
    }
185 190

  
191
    drop_map_check(objsql->get_name());
192

  
186 193
    return PoolSQL::drop(objsql, error_msg);
187 194
}
188 195

  
......
229 236

  
230 237
    if( mp_aux != 0 ) //Marketplace app already imported
231 238
    {
239
        reset_map_check(app->name);
232 240
        if ( mp_aux->version != app->version || mp_aux->md5 != app->md5 )
233 241
        {
234 242
            mp_aux->from_template64(t64, error_str);
......
255 263

  
256 264
        return oid;
257 265
    }
258

  
266
    insert_map_check(app->name);
259 267
    return PoolSQL::allocate(app, error_str);
260 268
}
261 269

  
src/market/MarketPlaceManagerDriver.cc
163 163
            }
164 164
        }
165 165
    }
166
    MarketPlaceApp *mp_app = nullptr;
167
    std::string error;
168
    std::string source;
169
    int rc_del;
170
    market = marketpool->get(id, true);
171
    set<int> apps_mp = market->get_marketapp_ids();
172
    market->unlock();
173

  
174
    for (set<int>::iterator i = apps_mp.begin(); i != apps_mp.end(); i++) {
175
        mp_app = apppool->get(*i, true);
176
        if ( mp_app != 0 )
177
        {
178
            if(apppool->test_map_check(mp_app->get_name())){ //delete app
179
                market = marketpool->get(id, true);
180

  
181
                source = mp_app->get_source();
182
                rc_del = apppool->drop(mp_app, error);
183

  
184
                market->del_marketapp(*i);
185
                marketpool->update(market);
186

  
187
                market->unlock();
188
                if ( rc_del < 0 )
189
                {
190
                    oss << " Error removing app from DB: " << error
191
                        << ". Remove app manually, source is: " << source;
192
                }
193
            }
194
        }
195
        mp_app->unlock();
196
    }
166 197

  
167 198
    oss << "Marketplace " << name << " (" << id << ") successfully monitored.";
168 199

  

Also available in: Unified diff